How can resume file transfer in WinSCP from where it is broken - windows

i am put command to upload files FTP server and each file like 3-5GB in size. Sometime server is disconnecting in between file transfer and when it reconnects it starts from broken file but it starts as fresh file. Example, if my download completes 99% then it disconnected and it is starting from the beginning of file.
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="D:\new\winscp_log\winscp_%yymmdd_hhmmss%.log" -rawtransfersettings PreserveTimeDirs=1 /command ^
"option batch abort" ^
"open ftps://***%%2Fsupport#***.com:%Password%#***.sharefileftp.com -hostkey="**" -rawsettings SendBuf=0 SshSimple=0 FtpPingType=0 -passive=on" ^
"put E:\MDR2\FILE_BACKUP /MDR2/FILE_BACKUP -neweronly -speed=0 -resumesupport=on" ^
"exit"

The documentation for the put command shows that there's a -resume option that is valid as long as you are using SFTP or FTP.
put E:\MDR2\FILE_BACKUP /MDR2/FILE_BACKUP -resume -neweronly -speed=0 -resumesupport=on

Related

Windows batch script to connect to SFTP server [duplicate]

I currently have batch scripts on different servers that transfer a csv file to an FTP server at a different location. My script looks similar to this:
echo user ftp_user> ftpcmd.dat
echo password>> ftpcmd.dat
echo put c:\directory\%1-export-%date%.csv>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.MyFTPSite.com
del ftpcmd.dat
If I wanted to require a secure transmission, is how would my script be updated?
Thanks.
First, make sure you understand, if you need to use Secure FTP (=FTPS, as per your text) or SFTP (as per tag you have used).
Neither is supported by Windows command-line ftp.exe. As you have suggested, you can use WinSCP. It supports both FTPS and SFTP.
Using WinSCP, your batch file would look like (for SFTP):
echo open sftp://ftp_user:password#ftp.MyFTPSite.com -hostkey="..." >> ftpcmd.dat
echo put c:\directory\%1-export-%date%.csv >> ftpcmd.dat
echo exit >> ftpcmd.dat
winscp.com /script=ftpcmd.dat
del ftpcmd.dat
And the batch file:
winscp.com /log=ftpcmd.log /script=ftpcmd.dat /parameter %1 %date%
Though using all capabilities of WinSCP (particularly providing commands directly on command-line and the %TIMESTAMP% syntax), the batch file simplifies to:
winscp.com /log=ftpcmd.log /command ^
"open sftp://ftp_user:password#ftp.MyFTPSite.com -hostkey=""...""" ^
"put c:\directory\%1-export-%%TIMESTAMP#yyyymmdd%%.csv" ^
"exit"
For the purpose of -hostkey switch, see verifying the host key in script.
Easier than assembling the script/batch file manually is to setup and test the connection settings in WinSCP GUI and then have it generate the script or batch file for you:
All you need to tweak is the source file name (use the %TIMESTAMP% syntax as shown previously) and the path to the log file.
For FTPS, replace the sftp:// in the open command with ftpes:// (explicit TLS/SSL) or ftps:// (implicit TLS/SSL). And remove the -hostkey switch.
winscp.com /log=ftpcmd.log /command ^
"open ftps://ftp_user:password#ftp.MyFTPSite.com -explicit" ^
"put c:\directory\%1-export-%%TIMESTAMP#yyyymmdd%%.csv" ^
"exit"
You may need to add the -certificate switch, if your server's certificate is not issued by a trusted authority.
Again, as with the SFTP, easier is to setup and test the connection settings in WinSCP GUI and then have it generate the script or batch file for you.
See a complete conversion guide from ftp.exe to WinSCP.
You should also read the Guide to automating file transfers to FTP server or SFTP server.
Note to using %TIMESTAMP#yyyymmdd% instead of %date%: A format of %date% variable value is locale-specific. So make sure you test the script on the same locale you are actually going to use the script on. For example on my Czech locale the %date% resolves to čt 06. 11. 2014, what might be problematic when used as a part of a file name.
For this reason WinSCP supports (locale-neutral) timestamp formatting natively. For example %TIMESTAMP#yyyymmdd% resolves to 20170515 on any locale.
(I'm the author of WinSCP)
The built in FTP command doesn't have a facility for security. Use cUrl instead. It's scriptable, far more robust and has FTP security.
ftps -a -z -e:on -pfxfile:"S-PID.p12" -pfxpwfile:"S-PID.p12.pwd" -user:<S-PID number> -s:script <RemoteServerName> 2121
S-PID.p12 => certificate file name ;
S-PID.p12.pwd => certificate password file name ;
RemoteServerName => abcd123 ;
2121 => port number ;
ftps => command is part of ftps client software ;

sftp batch file not able to execute

I have a windows batch file to connect from Server A (Windows) to
Server B (UNIX) via sftp to get a file. The script is as below:
sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg#hostnameB
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
exit
When I run the script it stops after running the first line i.e sftpg3 -oStrictHostKeyChecking=no...
D:\APPBASE\EAPSG\GEMSSG>sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg#hostnameB
Warning: ignoring unsupported option -o
Warning: ignoring unsupported option -o
Remote system type is POSIX.
sftp>
It didn't execute below lines:
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
If I run the command manually one line at a time it works.
Any idea why the script does not run completely?
Thank you.
That's because sftpg3 is a sftp like client which prompt an interactive session with the server waiting for input. so your first line in the script just opens the session and wait until that command (which is the prompt opened) to exit. you need to redirect the input into that prompted session (in unix like using <<) I don't know how it is done in windows. but if the aim from writing that script is to copy a file from the server you can just use scpg3

How to open teraterm SSH/Telnet connection from windows command prompt?

I got a solution to open a teraterm COM connection and run a macro -
"C:\Program Files (x86)\teraterm\ttermpro.exe" /I /C=7 /BAUD=115200 /M="E:\old data\Desktop\TTL\RvR\test.ttl"
However, need help on arguments to be given to open a SSH/Telnet connection to a particular host from cmd using teraterm and run a macro.
here is 100 percent working code for telnet to a remote host ip
send username password and a command on remote machine.
If you want to send any argument x as variable inside u can use VAR %x and %x% as its value
contents of test.ttl file in local folder as follows
start copy from next line by chanimg ip username and password
connect 'IP:23'
pause 2
sendln 'Remoteusername'
pause 2
sendln 'Remotepassword'
pause 2
logopen 'C:\Users\nocbb\test.txt' 0 0
sendln 'command on remote host'
pause 3
sendln 'logout'
logclose
end
copy till above line
Save as all files and test.ttl and
run in dos command
run using command
C:\Users\nocbb>"C:\Program Files (x86)"\teraterm\ttermpro /M=C:\Users\nocbb\test.ttl /nossh
Note Change the path as per installation folder of Teraterm in
ur installation of teraterm folder.

Scheduled batch file not running

I have a .bat file. If I run it manually (double click), it works. If I schedule it, it doesn't.
I tried solutions from similar questions on StackOverflow but none of them is working. Like:
Batch not scheduled
WIN 10 task scheduler
I changed general options.
Run no matter user connection
I changed the user starting the scheduled task.
Mine, BTW, has maximum permissions and when double clicked, it works.
I allowed maximum permissions.
Modified "Add argument" and "Start in"
I set no conditions in the "conditions" tab
I'm new to scripting, so it is possible I set something wrong.
That's my code:
#echo off
"C:\Program Files (x86)\WinSCP\winscp.com" /log=winscp.log /ini=nul /command ^
"open sftp://user:password#mySite.com -hostkey=""ssh-rsa 4096 xxxxxxxxx/yyyyw=""" ^
"option batch" ^
"option transfer binary" ^
"synchronize remote -filemask=""*.png>=2016-01-01<4M;*.jpg>=2016-01-01<4M "" \\FromFolder /destination/ -nopreservetime"
"exit"
If I put md C:\Temp & echo %TIME%>C:\Temp\Test.txt as 2° row, it writes the Test.txt file. If i put it in the end of the file it doesn't. No problems if i run it by double click.
I need the task to run the .bat file just as if I am double clicking it. I don't know if is it possible to open the shell or run it in background, as both of them are good for me. Let me know.
Thanks for suggestions.
Edit_1)
I removed the echo %TIME% >> C:\Temp\Test.txt and kept the "exit" >> C:\Temp\Test.txt .
If I double click my bat file, this is the log:
Host Search ...
Host connection ...
Authentication ...
Use username "xxxx".
Authentication with preset password
Authenticated.
Starting session ...
Session started.
Active session: [1] xxx#site.com
batch abort
transfer binary
Comparison...
Local 'file\MyFolder1' => remote '/ images'
Nothing to synchronize
Comparison...
Local 'H:\MyPath\MyFolder2' => remote '/ images'
Synchronization...
Local 'H:\MyPath\MyFolder2' => remote '/ images'
H:\MyPath\MyFolder2 image.JPG | 617 KB | 50.4 KB / s | binary | 100%
And it works perfectly.
If i run it from schedule (using my same user)
this is the log.
Host Search ...
Host connection ...
Authentication ...
Use username "xxxx".
Authentication with preset password
Authenticated.
Starting session ...
Session started.
Active session: [1] xxx#site.com
batch abort
transfer binary
Comparison...
Local 'file\MyFolder1' => remote '/ images'
Nothing to synchronize
Comparison...
Local 'H:\MyPath\MyFolder2' => remote '/ images'
Folder List Error Request 'H:\MyPath\MyFolder2\*.*'.
Error retrieving file list for "H:\MyPath\MyFolder2\*.*'.
System error. Code: 3.
The specified path could not be found
(I) nterrupt, (R) etry, (S) top: Stop
Folder List Error Request 'H:\MyPath\MyFolder2\*.*'
Error retrieving file list for "H:\MyPath\MyFolder2\*.*'
System error. Code: 3.
The specified path could not be found
I schedule the bat file using my user and max privileges so it should find the folder in the H:\ disk.
WinSCP most probably fails. I would guess that because the batch file working directory is not hat you think and winscp.log cannot be created there. Try using a path like for your debug test: C:\Temp\winscp.log.
The reason why the md C:\Temp & echo %TIME%>C:\Temp\Test.txt does not work at the end of your batch file is the exit command. You probably believe it's interpreted as WinSCP command. But it's not. You are missing ^ after the synchronize command. And additionally, you have a blank space after it. As a consequence, the exit is not part of WinSCP command-line, but it exits the batch file instead. Also the lines have to be indented (though I assume that it's rather due to your post formatting).
Try something like this:
#echo off
md C:\Temp
echo %TIME% > C:\Temp\Test.txt
"C:\Program Files (x86)\WinSCP\winscp.com" /log=C:\temp\winscp.log /ini=nul /command ^
"open sftp://user:password#mySite.com -hostkey=""ssh-rsa 4096 xxxxxxxxx/yyyyw=""" ^
"option batch" ^
"option transfer binary" ^
"synchronize remote -filemask=""*.png>=2016-01-01<4M;*.jpg>=2016-01-01<4M "" \\FromFolder /destination/ -nopreservetime" ^
"exit" >> C:\Temp\Test.txt
echo %TIME% >> C:\Temp\Test.txt
See also WinSCP FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?

Using ftp.exe to create some kind of log [duplicate]

I am writing a batch command to send data via FTP. Before sending the actual data I need to find if the FTP server is active/running. How do I check that in batch command?
The server responds with "220 server ready" message when it is connected.
Do something like this:
YourFTPCommand | find /i /v "220 server ready" && goto :ServerNotReady
Explanation:
Pipe the output of your FTP command to FIND
Do a case insensitive (/i) search for output that does not contain (/v) the string "220 server ready"
Go to someplace if such a string is found (&&)
I do not think there's a reliable way to do this with Windows ftp.exe.
It blindly keeps running the commands, no matter if connection or previous commands succeeded.
It won't even report the result via exit code.
All you can do is to parse the ftp.exe output.
You should better use a 3rd-party FTP client.
For example with WinSCP scripting you can use:
#echo off
winscp.com /log=ftp.log /command ^
"open ftp://user:password#example.com/" ^
"put c:\local\path\file.txt" ^
"exit"
If connection (the open command) fails, WinSCP won't execute the following commands (the put).
See also Converting Windows FTP script to WinSCP FTP script.
(I'm the author of WinSCP)

Resources