[英]linux script to automate ftp operation
I need to transfer a file from my linux server to a FTP server. 我需要将文件从我的linux服务器传输到FTP服务器。
My shell script is : 我的shell脚本是:
#! /bin/ksh
HOST='my_ip'
USER='userid'
PASSWD='password'
FILE='file.txt'
DIREC='/eir_log'
ftp -in $HOST << EOMYF
user $USER $PASSWD
binary
mkdir $DIREC
cd $DIREC
pwd
quit
EOMYF
pretty simple code. 非常简单的代码。 but the problem is though I am logging in the FTP server fine, but its not allowing me to create a new directory in the FTP server.
但问题是虽然我正在登录FTP服务器,但它不允许我在FTP服务器中创建一个新目录。 At first i thought some error with my script, but even individually if i run a
mkdir
in the ftp server its showing create directory failed
. 起初我认为我的脚本有一些错误,但即使是单独的,如果我在ftp服务器中运行
mkdir
,它显示create directory failed
。 Can somebody let me know the possible error, or if any eror in my code that i am missing out on.The pwd
is working fine though, which means there is no problem loging in the ftp site through script. 有人可以让我知道可能的错误,或者我错过了我的代码中的任何错误。虽然
pwd
工作正常,这意味着通过脚本登录ftp站点没有问题。
Thanks in advance for your help 在此先感谢您的帮助
Probably lftp ( ftp scripting client ) will be something you need ( look among your distro's packages ). 可能lftp(ftp脚本客户端)将是您需要的东西(查看您的发行版的软件包)。 Error creating directories is probably related to permissions of the dir inside which you try to create it.
创建目录时出错可能与您尝试创建目录的dir的权限有关。
Have you tried using SCP (Secure Copy)? 您是否尝试过使用SCP(安全复制)?
scp -r /dir/to/"file.txt" username@hostname scp -r /dir/to/"file.txt“username @ hostname
*if you're in the directory of the file/folder you wish to send then you don't need to define the complete filepath *如果您在要发送的文件/文件夹的目录中,则无需定义完整的文件路径
Have a look at this article if you want to scp without having to enter your password. 如果您想scp而不必输入密码,请查看本文。 http://www.thegeekstuff.com/2008/06/perform-ssh-and-scp-without-entering-password-on-openssh/
http://www.thegeekstuff.com/2008/06/perform-ssh-and-scp-without-entering-password-on-openssh/
If you are root or have admin privileges then you shouldn't need to sudo your way into making a directory. 如果您是root用户或拥有管理员权限,那么您不需要以自己的方式制作目录。 It will be best to run remote commands without sudo just in case a malicious code piggybacks your script
最好是在没有sudo的情况下运行远程命令,以防恶意代码捎带您的脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.