简体   繁体   English

传输完成后,PSFTP重命名文件

[英]PSFTP rename file after transfer completed

I am transferring files through PSFTP to 3rd party server using Batch files. 我正在使用批处理文件通过PSFTP将文件传输到第三方服务器。 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. 作为补救措施,第三方要求我们在开始文件传输之前用'.new'命名每个文件,并在文件完全/成功传输后删除'.new'。

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): 要重命名文件,请使用mv命令 (或它的ren别名):

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 . 有关类似的讨论,另请参阅SFTP文件锁定机制


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. 如果您需要使用带扩展名的解决方案,则可以使用WinSCP,因为它允许您自动使用临时文件名进行上载。 Though it uses .filepart , not .new extension. 虽然它使用.filepart ,而不是.new扩展名。

put -resumesupport=on c:\local\path\* /remote/path/

See WinSCP article on Uploading to temporary file name for more details. 有关更多详细信息,请参阅有关上载到临时文件名的 WinSCP文章。

The article also shows (a way more complicated) solution using WinSCP .NET assembly that allows you to use even the .new extension . 本文还展示了一种使用WinSCP .NET程序集的 (一种更复杂的) 解决方案,它允许您甚至使用.new扩展

If you choose to switch to WinSCP, there's a guide for converting psftp script to WinSCP . 如果您选择切换到WinSCP,则有一个将psftp脚本转换为WinSCP指南

(I'm the author of WinSCP) (我是WinSCP的作者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM