如何使用密码传输sftp?把命令不发送完整的文件

问题描述:

我是UNIX的新手。在寻找发送文件的正确方法方面需要帮助。如何使用密码传输sftp?把命令不发送完整的文件

我必须发送一个大文件1GB并且手动执行sftp所用的时间大约为10分钟,我们已经尝试了下面的脚本,因为我们必须使用密码登录。

这里的问题是在完全传输文件之前。脚本从SFTP连接中出来,没有错误。

脚本:

` expect -c " ` 
    spawn sftp ${remote_user}@${remote_host} 
    expect \"password\"      
    send ${remote_pswd}\r     
    expect sftp>        
    send \" cd ${remote_path}\r \"   
    expect sftp>        
    send \" lcd ${source_path}\r \"   
    expect sftp>        
    send \" put ${source_file} \r \"   
    expect sftp>        
    send \" echo $? \r \"     
    expect sftp>        
    send \"bye\" " '      ` 

登录:

` spawn sftp [email protected]        
[email protected]'s password:        
Connected to 192.168.79.15.           
sftp> cd /users/StoreStockManagement/ReferenceData/Inbound   
sftp> lcd /staging/oretail/external/data/DSPRD/Output/Pricing/INT340 
sftp> mput hhtstore_price.dat 
Uploading hhtstore_price.dat to /users/StoreStockManagement/ReferenceData/Inbound/hhtstore_price.dat 
hhtstore_price.dat 3% 189MB 18.1MB/s 04:31 ETA+ [[ 0 -ne 0 ]]` 

--Here传输文件的3%,这个剧本出来,我无法看到文件后出现。但是,当我手动尝试sftp它工作。只有脚本不能复制。

能有一个人在这里

帮助的expect命令的默认超时值是10秒。因此,在put之后,预计将等待10秒钟以查看提示,然后超时,然后继续执行脚本。

显然要等到但登录所必需的文件传输,所以添加到您的脚本:

set timeout -1