I'm transferring a small text file over FTP and trying to change the file extension after the transfer's been completed so the destination server can process the contents, how do I do this, the commands on winscp.net aren't particularly helpful but then again, I may be searching like an idiot.
rename oldname newname
If your client complains, try:
quote site rename oldname newname
This is old, but many FTP sessions won't allow you to change the file AFTER the transfer, as you have no permissions to do anything but dump the files into the FTP directory. Why can't they be changed prior to transfer?
If you want to rename file manually after transfer use Rename command:
https://winscp.net/eng/docs/task_rename
You can also configure WinSCP to transfer all files to temporary name and automatically rename them to final name after transfer finishes:
https://winscp.net/eng/docs/ui_pref_resume
In Python I got this code:
import ftplib
ftp_connect = ftplib.FTP(str_host)
ftp_connect.rename(str_oldName, str_newName)
Related
I am transferring files through PSFTP to 3rd party server using Batch files. While transferring files, due to buffering issues, files are being broken/not transferred fully.
As a remedy, 3rd party requested us to name each file with '.new' before starting file transfer and remove '.new' once file is transferred fully/successfully.
Please let me know Batch script commands to implement above. Please let me know if you need additional info.
To rename a file, use mv command (or it's ren alias):
put c:\local\path\file /remote/path/file.new
mv /remote/path/file.new /remote/path/file
Though if you are transferring multiple files using a wildcard, this won't help you.
A relatively simple solution for multiple files is using a temporary upload folder. After the upload finishes, you can move all files at once to the target folder:
mput c:\local\path\* /temp/path
mv /temp/path/* /remote/path
For a similar discussion, see also SFTP file lock mechanism.
If you need to use the solution with extensions, you can use WinSCP, as it allows you to automatically use a temporary file name for upload. Though it uses .filepart, not .new extension.
put -resumesupport=on c:\local\path\* /remote/path/
See WinSCP article on Uploading to temporary file name for more details.
The article also shows (a way more complicated) solution using WinSCP .NET assembly that allows you to use even the .new extension.
If you choose to switch to WinSCP, there's a guide for converting psftp script to WinSCP.
(I'm the author of WinSCP)
I need to make a script for an FTP server that will detect when a file is downloaded and then either rename or move or delete that file to prevent it from being re-downloaded. Is there a way to do this by storing a file on the FTP server that will always be looking for when a file is downloaded, and then executing that process? I assume it could be done with a bash script, but I dont know enough about them to know if it can be constantly running/checking for if a file is downloaded.
Thanks!
Using FTP commands I want to upload a large file once and then copy that file to many directories on the remote FTP server. All the copy commands seems to relate to copying from local to remote or the other way around.
Is there an FTP command to copy remote to remote?
are you trying to move the file? if yes, you can do it using rename command to move the file, as for copy i guess you still have to do the the get,send from local-remote way.
as for move command should be something like this
rename /oldpath/file2move.txt /newpath/file2move.txt
Basically just rename your file path that is infront of the file that you wish to move.
As far as I know, there is no such command available in FTP protocol. There are some extensions to SFTP protocol to do this (and, having SSH access, you can issue cp commands), but SFTP is not an FTP.
I have a pre-defined ftp link with a zip file on the other end that I want to save to a directory on my cloud server (running Windows Server 2008). Once the zip file has been saved to a specified directory, lets say "c:\MyZipFiles\ZipFile-1.zip" for example, I want to unzip the file so that all files contained within the zip file are accessible within the same directory. I'm currently doing this manually and I want to automate this process by creating a .bat or .cmd file that will perform these steps for me.
Once the zip file is unzipped, I have a task in the Task Scheduler of Windows Server Manager ready to use the unzipped files for other things.
The pre-defined link looks something like this:
ftp://idx.realtor.com/idx_download/files.zip
I would greatly appreciate anyone who can help me with this...
Batch file
ftp -s:ftp_cmds.txt host-name-goes-here
unzip local-file.zip
exit
ftp_cmds.txt
username-goes-here
password-goes-here
cd remote-directory-goes-here
get files.zip local-file-name-goes-here.zip
quit
This the batch file uses "unzip" to unzip the archive you can find it here: http://gnuwin32.sourceforge.net/packages/unzip.htm
Either put the binaries in the same directory or put them somewhere else and set your windows PATH
I used my own ftp to test most of this. Your ftp was offline for me, so it might take some tweaking but this should put you in the right direction.
Good evening.
Can You help me please with some batch file?
I have an ftp, where in root directory located few randomly named zip archives.
So i need to download that archives to local D:\temp
I know, how to do it via ftp.exe, but only for one file, witch name i know:
file: save.bat
ftp -s:1.txt
file: 1.txt
open myftp.com
123login
321pass
prompt
binary
hash
get file.zip D:\test\12.zip
bye
Maybe u can tell me how to download all * zip archives on ftp in loop?
Thanks!
You can use the mget command to download multiple files through ftp. This also supports wildcards.
You can simply use:
mget *.zip