Question about SFTP command

Hi All,

This is JCL that contain command script to copy file to destionation (UNIX)
I have 2 questions.

*********

//NATTOUT1 JOB ACCL,'XXXXYYYY',CLASS=A,MSGCLASS=X,                                 
//  NOTIFY=&SYSUID,REGION=0M,USER=SFTPXXX                                         
// SET PATH='/BBBB/XYX'                                                           
// SET USR='NATTNATT001'                                                           
//*****************************************************************               
//COPYOUT  EXEC PGM=IKJEFT01,DYNAMNBR=300,COND=EVEN                               
//*****************************************************************               
//SYSTSPRT DD SYSOUT=*                                                             
//DSIN     DD DSN=NNNN.FIX.LENGTH.OUTFILE,DISP=SHR                             
//HFSOUT   DD PATH='&PATH/CXCXS',                                                 
// PATHOPTS=(OCREAT,OTRUNC,OWRONLY),PATHMODE=SIRWXU                               
//SYSPRINT DD SYSOUT=*                                                             
//SYSTSIN  DD DATA,DLM='/>'                                                       
OCOPY INDD(DSIN) OUTDD(HFSOUT) BINARY                                             
/>                                                                                 
//CMDS     EXEC PGM=IKJEFT01                                                       
//INMVS    DD *                                                                   
cd /NATTNATT001/NATTNATT003/NAT0007IN                                             
pwd                                                                               
ls                                                                                 
put /BBBB/XYX/CXCXS VTESTX.TXT                                                     
!rm CXCXS                                                                         
!rm sftp.cmds                                                                     
!rm sftp1.sh                                                                       
quit                                                                               
//OUTHFS   DD FILEDATA=TEXT,                                                       
//            PATHOPTS=(OWRONLY,OCREAT,OTRUNC),                                   
//            PATHMODE=SIRWXU,                                                     
//            PATH='&PATH/sftp.cmds'                                               
//SYSTSIN  DD *                                                                   
  OCOPY IND(INMVS) OUTDD(OUTHFS)                                                   
/*                                                                                 
//SYSTSPRT DD SYSOUT=*                                                             
//SYSPRINT DD SYSOUT=*                                                             
//* create sftp shell script                                                       
//SH       EXEC PGM=IKJEFT01                                                       
//INMVS    DD *                                                                   
sftp -b sftp.cmds -oPort=4321 -oStrictHostKeyChecking=no $1@$2                     
//OUTHFS   DD FILEDATA=TEXT,                                                       
//            PATHOPTS=(OWRONLY,OCREAT,OTRUNC),                                   
//            PATHMODE=SIRWXU,                                                     
//            PATH='&PATH/sftp1.sh'                                               
//SYSTSIN  DD *                                                                   
  OCOPY IND(INMVS) OUTDD(OUTHFS)                                                   
//SYSTSPRT DD SYSOUT=*                                                             
//SYSPRINT DD SYSOUT=*                                                             
//*                                                                               
//UPLOADFL EXEC PGM=VCXBATCH,                                                     
//  PARM='sh  cd &PATH;./sftp1.sh &USR 999.999.999.99'                             
//STDOUT   DD  SYSOUT=*                                                           
//STDERR   DD  SYSOUT=*                                                           
//SYSOUT   DD SYSOUT=*

***************************

  1. Why we can create path to destination before we sign in to destination?
    or it just create command and at the end just execute step?

  2. If I would like to run this JCL by myself, I need to create the folder path in testing server ?

I run it myself but found error like this

IEF344I NATTOUT1 COPYOUT HFSOUT - ALLOCATION FAILED DUE TO DATA FACILITY SYSTEM ERROR
IGD17501I ATTEMPT TO OPEN A HFS FILE FAILED,                                   
RETURN CODE IS (00000081) REASON CODE IS (0594003D)                           
FILENAME IS (/BBBB/XYX/CXCXS)                                                 
IEF272I NATTOUT1 COPYOUT - STEP WAS NOT EXECUTED.

Thank you very much

  1. Set the home directory of the unix user to the destination directory.
  2. Not if the directory exists, and you have write permission.
put /BBBB/XYX/CXCXS VTESTX.TXT  
!rm CXCXS                    

This does not appear to be correct. Based on the put statement, the script is not running in the directory that contains the filef that you want to delete.
also i would not delete the source file until the transferred file has been processed.