Pragma Systems Technical Forum

sFTP file transfer

https://forums.pragmasys.com/Topic341.aspx

By Purvesh Kulkarni - 1/24/2016 10:11:43 PM

Hello All,




I have to transfer the files from our server to a remote location using sFTP. Is it possible to send the files using a single command instead of the script/batch file?

After authentication, we need to traverse to a path and then drop the file.

User:- Test_User

Server:- remotelocationalias

Private Key:- D:\SomeLocation\Private_Key

Landing Path:- landing_directory




I would appreciate if explanation is supported with an example or a Wiki link. I tried to look this up on Pragma Wiki/documentation, but could not find a suitable solution.




Regards,

Purvesh Kulkarni.
By bethredd - 1/25/2016 11:47:59 AM

Hello,

Unfortunately, there is not a way to pass all parameters on the command line as you wish. You must use a script to list the commands that should be performed after authentication. You can use scp with a single command line, if your server supports scp file transfers.

Using scp, your command would look something like this:

scp -oidentityfile2=d:\somelocation\public_key Test_User@remotelocationalias:landing_directory\file
Using sftp you would need a script with the following:

put file

Your command line would then look like:

sftp -oidentityfile2=d:\somelocation\public_key -b batchfile test_user@remotelocationalias

Full instructions on using sftp with a batch file can be found at www.pragmasys.com/ssh-server/topics/idh-sftp.htm
By Purvesh Kulkarni - 2/2/2016 1:18:32 AM

Thanks bethredd.




The batch script works, however, after completion of command when I check the ERRORLEVEL variable in Windows Batch Script, it returns -1. However, the file is delivered to the destination. 




Checking the Pragma documentation, successful transfer should return 0. Can you help me understand and fix this?

I wish to raise an error flag, if return code is a failure.