Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Code for uploading a file to unix server and deletion of local files

saikrishna wrote:

I have requirement that i need to upload files(two or four) from unix(SFTP Serevr) and windows machine, after successful transfer, we need to remove the local files.

As i am very new to this, Could you please suggest and provide sample code.

This topic covers your question. What do you need more?

See also this article, which covers similar topic:
https://winscp.net/eng/docs/script_local_move_after_successful_upload
martin

Re: Code for uploading a file to unix server and deletion of local files

saikrishna wrote:

I have requirement that i need to upload files(two or four) from unix(SFTP Serevr) and windows machine, after successful transfer, we need to remove the local files.

As i am very new to this, Could you please suggest and provide sample code.

This topic covers your question. What do you need more?

See also this article, which covers similar topic:
https://winscp.net/eng/docs/script_local_move_after_successful_upload
saikrishna

Code for uploading a file to unix server and deletion of local files

Hi,

I have requirement that i need to upload files(two or four) from unix(SFTP Serevr) and windows machine, after successful transfer, we need to remove the local files.

As i am very new to this, Could you please suggest and provide sample code.

Thanks & Regards
Saikrishna
Loas

Guys, it is possible to remove a local file in the script?

Thanks in advance.


Loas
Guest

Excellent, Great! Sometimes it is the simple things, eh? I was using version 3.7.1, so that was the problem. I installed 3.7.4 and it worked just as expected.

Thanks so much for your assistance with this issue, I think it has been resolved!
martin

I have tried your batch file on following dummy script without opening session first, so that "upload" fails with "no session":
option batch on

upload xxx
exit

And it works as expected. Can you try this simple case?

BTW, what version of WinSCP are you using? Error exit code is returned only since version 3.7.1. Also does your command winscp3 (in bach file) execute winscp3.exe or winscp3.com? If winscp3.com, you need to use at least 3.7.3.
Guest

Thanks for your reply. I have done as you suggested (unless I misunderstood you), so the batch would now be:

@ECHO OFF
CD\PROGRA~1\WINSCP3
WINSCP3 /CONSOLE /SCRIPT=UPLOAD.TXT docstar
IF ERRORLEVEL 1 GOTO FAILURE
IF ERRORLEVEL 0 GOTO SUCCESS

:SUCCESS
ECHO FILES SUCCESSFULLY UPLOADED!
DEL C:\import\*.tif
GOTO END

:FAILURE
ECHO ERRORS DURING TRANSFER. FILES _NOT_ UPLOADED.

:END

However, if the DSL line is out, I receive a message, "Copying files to remote side failed....session 'upload' failed....No session." At this point, the batch file continues on to delete the client side files and display "FILES UPLOADED SUCCESSFULLY!"
So, it would seem that for whatever reason (probably an error in my batch file) that an error code is not being picked up and a branch is not occuring as I would like.

Thanks again for your assistance!
martin

The first problem I see is that "IF ERRORLEVEL 0" is always true as the "IF ERRORLEVEL N" succeeds when "the last application returned exit code N or greater". Just try to swap order of the two "IF ERRORLEVEL" commands. Let me know if it does not help.
Guest

Thanks for the addional help, I understand what you are saying about accomplishing my goal via batch file, but I guess I just do not have the knowledge of HOW to do it.

Something like this?

@ECHO OFF
CD\PROGRA~1\WINSCP3
WINSCP3 /CONSOLE /SCRIPT=UPLOAD.TXT UPLOAD
IF ERRORLEVEL 0 GOTO SUCCESS
IF ERRORLEVEL 1 GOTO FAILURE

:SUCCESS
ECHO FILES SUCCESSFULLY UPLOADED!
DEL C:\FILES\*.tif
GOTO END

:FAILURE
ECHO ERRORS DURING TRANSFER. FILES _NOT_ UPLOADED.

:END

This didn't work (because I don't know what I am doing I suspect), I believe the problem is that I don't know enough about exit/error codes and how to implement them properly into a batch file to do this.

I realize this is not your fault or problem; but if you know right off, I would appreciate it if you could elaborate. If not, thanks anyway for the help offered already.
martin

Re: Deleting local files after successful transfer via script

Any idea of a good way of deleting these after they have tranferred via a batch file? I am concerned about them getting deleted before the upload completes. I supposed I could just have scheduler delete whatever is there the next morning; but if for some reason the upload failed (interrupted internet access, power outage, etc) I would be concerned that it might result in lost files.

As I've wrote before, run winscp from windows batch file (.bat) and once it successfully finishes (exit code 0), remove the local files using windows command 'del'.
Guest

Re: Deleting local files after successful transfer via script

martin wrote:

You can run the WinSCP script from batch file that will remove the local file after the WinSCP finishes. Next version of WinSCP will maybe support execution of local commands directly.


Thanks for your reply. I think that would be a useful feature for situations like this; I thought maybe it was possible and I was just overlooking it since local files can be deleted via the GUI...

Any idea of a good way of deleting these after they have tranferred via a batch file? I am concerned about them getting deleted before the upload completes. I supposed I could just have scheduler delete whatever is there the next morning; but if for some reason the upload failed (interrupted internet access, power outage, etc) I would be concerned that it might result in lost files.

Maybe this is just a concern I will have to deal with; but if you had something in mind I would appreciate it if you would share it.

Thanks!
martin

Re: Deleting local files after successful transfer via script

You can run the WinSCP script from batch file that will remove the local file after the WinSCP finishes. Next version of WinSCP will maybe support execution of local commands directly.
Guest

Deleting local files after successful transfer via script

Hi, I apologize in advance if this I have missed this information somewhere, but is there a way to remove local files once they have been succefully updated via a script?

For example, right now I have a machine automatically uploading to a remote linux server from a Windows workstation. I would like the first workstation to delete the local files once they have been uploaded, but I do not know what the command/syntax would be to accomlish this (if it exists)?

For example, on the first machine I might have something simple like this running via task scheduler:

option batch on
option confirm off
open user:user@255.255.255.255
option transfer binary
put C:\import
%%% I would like a command to delete the files in C:\import here :) %%%
close
exit

Can anyone tell me how I can accomplish this?

Thanks!