Patrick99
(Fresh Scripter)
2017-09-07 09:03 PM
how to use SFTP instead of FTP transfers

Dear friends
currently i'm using FTP to transfer some cleartxt data from a client to a server because its not business data, but now I would include confidenial data so we have to swing over to SFTP server. how can I convert my script?
 Code:
 $local="c:\windows\test"
 $Patch="c:\windows\test"
 $dirs="cd"
 $site2="62.xx.xx.xx"
 $site2_user="test\Bello"
 $site2_pw="Belloxxxxx"
 
:ftp_files
 Del "c:\windows\test\ftp.cmd"
 If (Open(1,"c:\windows\test\ftp.cmd",5) = 0)

  $nul=WriteLine(1,"open $site2"+Chr(13)+Chr(10))
  $nul=WriteLine(1,"$site2_user"+Chr(13)+Chr(10))
  $nul=WriteLine(1,"$site2_pw"+Chr(13)+Chr(10))
  $nul=WriteLine(1," binary"+Chr(13)+Chr(10))
  $nul=WriteLine(1," status"+Chr(13)+Chr(10))
  $nul=WriteLine(1," mkdir"+ " Easy_reports\" + $NAME + Chr(13)+Chr(10))
  $nul=WriteLine(1," cd"+Chr(13)+Chr(10))
   $nul=WriteLine(1," FEasy_reports\" + $NAME +Chr(13)+Chr(10))
   $nul=WriteLine(1," lcd "+ $Patch + Chr(13)+Chr(10))
   $nul=WriteLine(1," mput $local\*.*"+Chr(13)+Chr(10))
   $nul=WriteLine(1," delete "+ "test.exe" + Chr(13)+Chr(10))
   $nul=WriteLine(1," delete "+ "ftp.cmd" + Chr(13)+Chr(10))
   $nul=WriteLine(1,"close"+Chr(13)+Chr(10))
   $nul=WriteLine(1,"quit"+Chr(13)+Chr(10))
   If Close(1)
   EndIf
 EndIf
 Sleep 2
 Shell '%comspec% /c ftp -d -i -s:c:\windows\test\ftp.cmd '
 Sleep 15


Mart
(KiX Supporter)
2017-09-08 09:17 AM
Re: how to use SFTP instead of FTP transfers

ftp.exe that is included in the OS does not support SFTP at the moment. That may change but that would be up to Microsoft.
swicthing to WinSCP should do the trick.

An example: https://stackoverflow.com/questions/21102193/replace-windows-command-ftp-se-ftpscript-txt-with-sftp


BradV
(Seasoned Scripter)
2017-09-08 11:38 AM
Re: how to use SFTP instead of FTP transfers

Putty is another option. Also, just a short difference between sftp and scp which is more important when scripting. If you use sftp and open a session, even if none of the files get transferred, sftp will close without any errors. It is a batch session. If you use scp, each transaction will tell you the success or failure of the transfer. So, you can keep track of the results better.