我正在使用Bash脚本通过FTP备份我的web文件。正如标题所说,我有一个Ubuntu网络服务器,并且正在备份到Windows机器上。我在Windows机器上有一个ssh程序和FileZilla Server,可以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
其他变量有点敏感,所以我不想发布它们,但是凭证到目前为止一直对我有效。
我得到的错误看起来像这样:
sftp> cd C:UsersTech1testserverbackup
Couldn't stat remote file: No such file or directory
我已经ssh到文件夹和sftp,所以我不确定问题是什么。cd是windows自带的命令,不只是FTP命令。
你知道出了什么问题吗?谢谢你。
sftp> cd C:UsersTech1testserverbackup
Couldn't stat remote file: No such file or directory
这是由于FTP服务器没有挂载驱动器号的概念,而Windows系统有。
您可以使用pwd
来连接到FTP以确定您当前所在的目录:
sftp> pwd
/C/Users/Tech1
…它显示在您的环境中,FTP管理员将Windows C:
驱动器映射到FTP服务器中称为C
的常规文件夹(并将所有其他挂载的驱动器映射到文件夹)。
您可以更改Linux中此目录的所有权:
$ sudo chown $USER /path/directory
我在这里找到了这个解决方案