WinSCP – want to upload multiple files

Advertisement

gnanasundram
Joined:
Posts:
3
Location:
Hyderabad

WinSCP – want to upload multiple files

Hi,

I am using winscp.exe to upload the file to server, but i am face some problem while uploading the files.
If I send a file by using the command put abc.txt then the file is uploaded successfully.
But I want to upload multiple file so i used below command.
put *.csv
or
put *.*
command, it says the file not found.

Can you please suggest on this and give a solution the error.

Thanks in advance
Regards,
Gnansundram

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: Winscp- want ot upload multiple files

What is the actual problem?
  1. There are files matching the mask and WinSCP does not find them
  2. There are indeed no files matching the mask and you want WinSCP to silently do nothing
Also what version of WinSCP are you using?

Reply with quote

gnanasundram
Joined:
Posts:
3
Location:
Hyderabad

Hi,

Thanks for your response.
I want to upload a file to server using SFTP and for that I use winscp.exe (using GUI working fine) WinSCP version 3.7.1
Now I want to automate the file transfer.
I tried the below script for automation:
Batch file
start "D:\new test\" winscp.exe /console /script=sample.txt"
Sample.txt
open username:password@ipaddress:10022
option batch on
option confirm off
cd /filename
put "Z:\*.csv"
Now when I click on bat file it connect to server and get stopped in the put command and shows an error file not found. But when I give file put filename.csv then the file gets uploaded.

Reply with quote

TimU
Joined:
Posts:
23
Location:
Sydney

Your SAMPLE.TXT script seems flawed.

Try this:
Sample.txt
# Automatically abort script on errors 
option batch abort 
# Disable overwrite confirmations that conflict with the previous 
option confirm off 
# Force binary mode transfer 
option transfer binary 
# Establish the connection 
open username:password@ipaddress:10022
# Change the Local Directory 
lcd "Z:\"
# Change to the correct Remote directory 
cd /<RemoteDirectory>
# List the local files 
lls 
# List Remote Files
ls
# Upload *.csv
put "*.csv"
This will give you a list of the Local Directory and the Remote Directory so you can be sure you're looking at the correct locations.

I'm assuming that Z: refers to a mapped network drive? Pls be aware that this won't be available if you're planning on running this script as a scheduled task, unless you map it manually in the tasks batch file.

You're better off using this command to be universally accessible:
# Change the Local Directory 
lcd "\\servername\share"
Hope this helps.
Tim

Reply with quote

Advertisement

Guest

Hi,
Thanks for sample script, but I am getting the same error.
I followed the same step which you have given. But I am getting the below error
winscp>put *.CSV
*.csv    0kb  0.0kb/s binary 0%
file or folder '*.csv' does not exit
But when I give filename.csv transfer is successful – shows below message.
winscp>put filename.csv
filename   0kb  0.1kb/s binary : 100%
But I want to transfer multiple file at a time.

Thanks and Regards,
Gnanasundram

Reply with quote

martin
Site Admin
martin avatar

Re: Winscp- want ot upload multiple files

3.7.1 does not support file masks in scripting commands. Please upgrade to the latest version.

Reply with quote

gnanasundram
Joined:
Posts:
3
Location:
Hyderabad

Re: Winscp- want ot upload multiple files

martin wrote:

3.7.1 does not support file masks in scripting commands. Please upgrade to the latest version.
Hi,
Thanks for your response,
I have installed WinSCP (version 4.3.3) in my machine.
The script is working fine.
But while sending file it show an error stating that "Ignore permission errors" while sending the file.
please guide me how to correct the error.

Thanks and regards,
Gnana sundram.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: Winscp- want ot upload multiple files

Have you read these?

Reply with quote

Advertisement

clt
Guest

Order of uploading files

Hi @Martin, or anybody..
Is it possible to control the order of files uploading on the server? I have .gpg and .chk files and WinSCP upload .chk first (I assume that in alphabetical order). I need to upload e.g. first.gpg, then first.chk, second.gpg then second.chk etc. Thank you!

Reply with quote

TimU
Joined:
Posts:
23
Location:
Sydney

Re: order of uploading files

@clt: You could either:
  1. Script it externally then call WinSCP with a known list of files to transfer.
  2. Run multiple WinSCP passes over your source directory, first transferring *.gpg, then *.chk.
Here's an extract of a Windows Batch script that will append file names to an existing SFTP Batch Script
DIR /a-d /b *.gpd %source.path% >%SFTP.batch.filelist%
DIR /a-d /b *.chk %source.path% >>%SFTP.batch.filelist%
 
:: If there are no files in the source directory to transfer, leave the script.
if errorlevel==1 (@ECHO Nothing To Do - Exiting Script)&(Goto :EOF)
 
@ECHO File Listing Complete
 
:: Now echo the file names to the script, including the SFTP.OPERATION we want to perform.
@ECHO Echo the file names to the SFTP Script file
for /f "tokens=*" %%A in (%SFTP.batch.filelist%) do (echo PUT -preservetime "%%A" >>%SFTP.batch.script%)

Reply with quote

Advertisement

You can post new topics in this forum