【问题标题】:Create file after transferring via SFTP通过 SFTP 传输后创建文件
【发布时间】:2020-04-07 17:50:32
【问题描述】:

在为特定用户成功完成 SFTP 传输后,如何自动创建一个与源文件同名但附加“.transferred”扩展名的空文件?

示例

scp /home/somefile.txt someuser@someserver:/somedirectory/somefile.txt

完成此传输后,我希望在源服务器上传输 somefile.txt.transferred。

我怎样才能做到这一点?

提前致谢。

【问题讨论】:

    标签: bash sftp


    【解决方案1】:

    使用 bash,您可以这样做:

    # The following line defines the name of the file you are scp-ing to destination
    FILE=somefile.txt
    
    # Now you do the scp
    scp /home/$FILE someuser@someserver:/somedirectory/$FILE
    
    # Adding a temporary variable so that we can define name of the file to be touched
    TRANS=".transferred"
    TOUCH_FILE="$FILE$TRANS"
    
    #Now we create the empty file that you wanted
    touch /home/$TOUCH_FILE
    
    #Confirm that it got created
    ls -l /home/$TOUCH_FILE
    

    【讨论】:

    • 谢谢@Mamun。这会起作用,但是我需要为我传输的每个文件更改脚本。我正在寻找的是为从特定文件夹传输的每个文件运行此功能。
    猜你喜欢
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 2013-01-27
    • 2016-02-18
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多