简体   繁体   English

无法使用Expect通过远程服务器中的sftp转换所有文件

[英]Unable to mput all the files through sftp in the remote server using expect

I'm trying to mput all files present in the directory : /Test/XML/ into a remote sftp server with the help of expect utility. 我想mput出现在目录中的所有文件: /Test/XML/成的帮助下远程SFTP服务器expect效用。

I've around 320 files in the directory: /Test/XML/. 我在/ Test / XML /目录中大约有320个文件。

The size of each file is around 0.1 MB. 每个文件的大小约为0.1 MB。

There's no error observed. 没有观察到错误。

Here's my code: 这是我的代码:

cd /Test/XML/

/usr/bin/expect <<EOF
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}\r"
expect "sftp>"
send "cd /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
EOF 

But the problem here is, mput * is transferring only 4 files instead of transferring all the 320 files. 但是这里的问题是, mput *仅传输4个文件,而不是传输所有320个文件。 Not sure, why it's not able to transfer all the 320 files in the remote server. 不确定,为什么它不能传输远程服务器中的所有320个文件。

Any help is most welcome. 任何帮助都是最欢迎的。

Thanks @ThiruShetty for the hint of using set timeout -1 in the expect utility. 感谢@ThiruShetty使用的提示set timeout -1expect效用。

Actually, i had a lot of files(~320-350) to be transferred(sftp) to a remote server. 实际上,我有很多文件(〜320-350)要传输(sftp)到远程服务器。 With the normal execution of sftp using expect utility, it was able to transfer only a few files, not all of them which i wanted. 随着正常执行sftp使用expect效用,它能够传递只有少数文件,不是所有的人,我想要的。

After inserting set timeout -1 inside expect , it solved the problem of timeout. expect插入set timeout -1后,解决了超时问题。

Here's the final code: 这是最终代码:

cd /Test/XML/

/usr/bin/expect <<EOF
set timeout -1
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}\r"
expect "sftp>"
send "cd /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
EOF

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

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