1

I am currently FTP'ing file to a unix box from a windows server. I want to change the following section of the script and migrate the ftp process to be sftp.

@echo off
echo user %user%> ftpcmd.dat
echo %password%>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %filetobeuploaded% %filepath%%File%>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat %host%
del ftpcmd.dat
:END

I have PSFTP.EXE installed on my windows directory. Using that can I send the files with SFTP ?

How can I replace line ftp -n -s:ftpcmd.dat %host% to be SFTP. I understand you can do something like this....

CALL PSFTP.EXE someUserName@54.54.54.54 ....

If anybody is familiar, please can you help me complete it. what arguments would I give. user, pw, remotedir, host details are kept in a properties file. Im looking to use keys instead of password. Can you pass the existing ftpcmd.dat arg to psftp?

3
  • Please note, SFTP is NOT FTP + SSL. That is called FTPS. SFTP is a SSH based protocol, so you can upload to an SSH server with it, but not an FTP server. if you want to upload to an FTP server look into FTPS. see here for some info on the differences: superuser.com/questions/677966/ftps-versus-sftp-versus-scp/… Aug 14, 2014 at 16:22
  • I guess what Im trying to ask above is how I maintain most of the written script above for ftp and make a small change to send it as sftp by using psftp.exe.
    – M06H
    Aug 14, 2014 at 16:38
  • Have you tried psftp -l %user% -pw %password% -b sftpcmd.dat %host% where "sftpcmd.dat" contains put %filetobeuploaded% %filepath%%FILE% on one line and quit on another? The biggest difference here seems to be that as is usually the case with ssh-oriented clients, the username must be specified when the command is called, rather than supplied after the fact as with traditional FTP.
    – 0xDAFACADE
    Aug 14, 2014 at 17:57

1 Answer 1

1

You can also use WinSCP. It supports both the SFTP and scripting.

See the guide for converting Windows FTP script to WinSCP SFTP script.

The script will look like:

open sftp://%user%:%password%@%host%
put -transfer=binary %filetobeuploaded% %filepath%%File%
exit

You can run the script like (if saved to script.txt):

winscp.com /script=script.txt

Note that (contrary to the ftp.exe), environment variables are resolved in WinSCP script too.

If you want to use a private key file, use:

open sftp://%user%@%host% -privatekey=path\key.ppk

(I'm the author of WinSCP)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.