Dan
Dan

Reputation: 77

Files are not present in SFTP directory after upload using WinSCP

I need a script that will copy files to an SFTP server using WinSCP.

My txt file so far :

# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on

# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on

# Disable overwrite confirmations that conflict with the previous
option confirm off

# Connect using a password
# open user:[email protected]
# Connect
open sftp://***:***@***.fr/ -hostkey=*

# Force binary mode transfer
option transfer binary

# Interface 1
cd /tracks
lcd "Y:\"

#Copie des données en local
get *.txt

#Envoie de données sur le serveur
put *.*

#Effacement des données
put -delete "Y:\*.txt"

# Interface 2
cd /trackm
lcd "Y:\"

#Copie des données en local
get *.tar-gz*

#Envoie de données sur le serveur
put *.*

#Effacement des données
put -delete "Y:\*.tar-gz*"

#Disconnect
#close

#Exit WinSCP
#exit

My bat file so far :

@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"

So far it doesn't upload the files, but it deletes them.

Upvotes: 1

Views: 1903

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202222

Your script makes a little sense.

If you want a simple script that moves all Y:\*.txt files to /tracks and all Y:\*.tar-gz* files to /tracksm, replace all your script after the open command with:

put -delete Y:\*.txt /tracks/
put -delete Y:\*.tar-gz* /trackm/
exit

See documentation of put command.


Though it seems that although the original script was quite ugly and inefficient, it probably did its job.

The root problem is that your server probably does some processing with the uploaded files and deletes or moves away the files after they are processed.

That's quite common behavior with servers that processes file (as opposite to storing files).
See WinSCP FAQ Why is uploaded file not showing in a remote directory or showing with a different name?

Upvotes: 1

Related Questions