bash “无法统计远程文件:没有这样的文件或目录”:在从 *nix 到 Win 的 shell 脚本中使用 FTP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24790058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:53:05  来源:igfitidea点击:

"Couldn't stat remote file: No such file or directory": Using FTP in shell script from *nix to Win

linuxbashshellsshftp

提问by JFA

I'm using a Bash script to backup my webfiles via FTP. As the title says, I have an Ubuntu webserver and am backing up to a Windows machine. I have an ssh program and FileZilla Server on the Windows machine, and can SSH and SFTP into it. The core of the script looks like this:

我正在使用 Bash 脚本通过 FTP 备份我的网络文件。正如标题所说,我有一个 Ubuntu 网络服务器并且正在备份到一台 Windows 机器。我在 Windows 机器上有一个 ssh 程序和 FileZilla 服务器,并且可以通过 SSH 和 SFTP 进入它。脚本的核心如下所示:

SRCDIR="C:\Users\Tech1\testserverbackup"
DATAIN="/var/www/html/"
FILENAME="-r *"

sshpass -e sftp -oBatchMode=no -b - ${USER}@${LANHOST} << EOF
cd  ${SRCDIR}
lcd ${DATAIN}
mkdir $(date -I)
cd $(date -I)
put ${FILENAME}
bye
echo made it
EOF

The others vars are a bit sensitive, so I don't want to post them, but the credentials have been working for me so far.

其他变量有点敏感,所以我不想发布它们,但到目前为止凭据一直在对我来说有效。

The error I'm getting looks like this:

我得到的错误是这样的:

sftp>       cd  C:\Users\Tech1\testserverbackup
Couldn't stat remote file: No such file or directory

I've ssh'd into the folder and sftp'd, so I'm not really sure what the issue is. AFAIK, cd is the native windows command, not just the FTP one.

我已经 ssh 进入文件夹并 sftp 了,所以我不确定问题是什么。AFAIK, cd 是本机 Windows 命令,而不仅仅是 FTP 命令。

Any ideas what's going wrong? Thank you.

任何想法出了什么问题?谢谢你。

采纳答案by admdrew

sftp>       cd  C:\Users\Tech1\testserverbackup
Couldn't stat remote file: No such file or directory

This is due to FTP servers not having the concept of drive letters for mounts, as Windows systems do.

这是因为 FTP 服务器没有安装驱动器号的概念,就像 Windows 系统那样。

You can use pwdto while connected to FTP to determine the directory you're currently in:

您可以pwd在连接到 FTP 时使用 来确定您当前所在的目录:

sftp> pwd
/C/Users/Tech1

...which shows that in your environment, the FTP administrator mapped a Windows C:drive to a regular folder called Cwithin the FTP server (and mapped all the other mounted drives to folders).

...这表明在您的环境中,FTP 管理员将 WindowsC:驱动器映射到CFTP 服务器内调用的常规文件夹(并将所有其他安装的驱动器映射到文件夹)。