3

I'm sending a file from a mainframe host to a linux ftp sever using sftp.

I want to append the date to the filename once the file resides on the linux box. (Ex: filename.txt becomes filename122308.txt)

I have tried the 'rename' command using 'date +%m%d%y' - the file was renamed but the flags were not executed (The filename became filename'date +%m%d%y'.txt

The 'cp' and 'mv' commands do not work... any ideas?

Thanks.

4

6 回答 6

1

由于 sftp 没有运行 shell,因此没有什么可以执行该date命令。您可能必须在发件人方面评估您想要的新名称,然后执行 sftp 重命名。

另一种选择是将文件发送到队列区域(例如带有您的日期字符串的文件夹),并在 linux 框上设置一个脚本相应地移动/重命名接收到的文件。

于 2008-12-23T19:38:46.727 回答
1

这些命令是通过 JCL 控制卡发送的。我认为这种方法行不通。

于 2008-12-23T17:15:32.070 回答
0

你可以通过命令行来做吗?存在执行 sftp 的选项...

sftp [[user@]host[:file [file]]]

...所以你可以执行...

export WHEN=`date +%m%d%y`
sftp theUser@theHost:filename$WHEN.txt filename.txt <<-!
thePassword
!
于 2008-12-23T17:10:56.307 回答
0

您可以访问 Linux 服务器吗?在这种情况下,您可以在那里重命名文件。例如,您可以使用 inotify 来监视目录,然后使用脚本在该目录中创建新文件时将日期添加到文件中。

这是Python 中的一个简单示例(尽管大多数语言都有 inotify 绑定)。您要监听的事件是 IN_CREATE。

于 2008-12-24T09:40:37.557 回答
0
#Establish a local variable to store the LOGINID to be used
export USERID=xxxxx                                                  
#Establish a local variable to store the Path/file location on Remote machine
export REMOTEPATH=/some/path/    
#Establish a local variable to store the NAME of the remote Server
export TARGET=192.168.0.xx
#Establish a local variable to store the new component of the file name (in
#this case, a modification of Date)
export WHEN=`date +%m%d%y`                                                  
#Demonstrate that the USERID variable is set properly by echoing it out to the
#StandardOut
echo "User "$USERID                                               
#Demonstrate that the TARGET variable is set properly by echoing it out to the
#StandardOut
echo "Target Server: "$TARGET                              
#Demonstrate that the REMOTEPATH / server variable is set properly by echoing
#it out to the StandardOut
echo "Target Path "$REMOTEPATH                                    
#Demonstrate that the WHEN / date name modication variable is set properly by
#echoing it out to the StandardOut
echo "Date component of file "$WHEN                                  
#Just echo out that we're about to do something useful
echo "Sending file to REMOTE"                                        
#Simulate the user typing out a command by using the "echo" command.  We use
#the $REMOTEPATH and $WHEN variables to modify "what the user types" but when
#we're done, echo passes information into SFTP just like the user were sitting
#there typing in the #commands.  In this case, it should send in 
#"put /local/path/file /some/path/fileName09092009.txt"
#That is provided as the command list to sftp because of the single "-" that 
#says "get my list of commands from standard-input"  The -vvv is for verbose 
#(lots of diagnostics) and then the $USERID@$TARGET uses the USERID and TARGET
#variables to connect as user-at-server for the exchange.
#A passwordless SSH authentication is already in place, so no password 
#is needed.
echo "put  /local/path/file $REMOTEPATH/fileName$WHEN.txt " | \
    sftp -b - -vvv $USERID@$TARGET
#Just echo out that we're about to do the next step and change file
#permissions.
echo "Changing file Permissions on REMOTE"                
echo "Done"                                          
于 2009-09-21T17:34:33.200 回答
0

不确定您的大型机 SFTP 客户端,但许多 SFTP 客户端支持使用 ! 运行本地操作系统命令的前缀。因此您可以在发送前将文件复制到新名称,然后发送,然后删除副本。

例如:

!cp filename.txt filename122308.txt
put filename122308.txt
!rm filename122308.txt
exit

如果空间很宝贵,请使用两次 mv 而不是 cp & rm。

于 2010-08-10T00:06:57.157 回答