2013-01-24 95 views
0

道歉我知道这是一个很好涵盖的问题,但我似乎找不到任何简单的解决方案...FTP/WPUT,任何简单的工作解决方案?

试图得到一个问题整理出来,我希望somone能够协助。

我正在创建一个脚本,而我能想到解决这个问题的唯一方法就是通过FTP将文件传输到远程Web服务器。

.sh脚本,我最初尝试过FTP,但似乎有这样做与密码有关的问题,我尝试了一些解决方法,但这并不奏效。

我已经尝试了wput,但似乎也失败了。

#!/bin/sh 
wput -v file.php ftp://usr:[email protected]/docroot/ 

bash wput.sh 
wput.sh: line 2: $'\r': command not found 
--12:20:58-- `/file.php' 
    => ftp://user:[email protected]/docroot/ 
Connecting to host.co.uk:21... connected! 
Logging in as user ... Logged in! 
==> CWD docroot 
==> TYPE I ... done. 
... failed. 
==> SYST ... done (UNIX Type: L8). 
==> PASV ... done. 
==> TYPE A ... done. 
==> LIST ... done. 
==> TYPE I ... done. 
==> PASV ... done. 
' not understood) Skipping this file 
FINISHED --12:20:59-- 
Transmission of 1 file failed. 
wput.sh: line 4: $'\r': command not found 
wput.sh: line 5: $'\r': command not found 

有人能告诉我我哪里出错了。这可能是一个文件权限问题或什么?

我所需要的只是简单的解决方案,以简单的方式自动将文件从我的电脑传输到某些网页空间。

感谢

+1

您能够运行'wput -v file.php的ftp:// USR:通过@ host.co.uk /文档根目录/'孤独,在一个shell?另外,你使用的是Windows吗? – Rubens

+0

看到'\ r'后,我强烈怀疑windows文件EOL问题。 – askmish

+0

不使用Windows,我使用的机器是UBUNTU [Linux]。奇怪的是,如果该文件不存在于另一个虚拟主机上,它就会起作用。但是,一旦它在那里,就会跳过。我认为我需要强制它覆盖 – ablueman

回答

1

尝试使用ncftpput

例子ncftpput帮助菜单显示:

ncftpput -u gleason -p my.password Elwood.probe.net /home/gleason stuff.txt 
    ncftpput -u gleason Elwood.probe.net /home/gleason a.txt (prompt for pass) 
    ncftpput -a -u gleason -p my.password -m -U 007 Bozo.probe.net /tmp/tmpdir a.txt 
    tar cvf - /home | ncftpput -u operator -c Server.probe.net /backups/monday.tar 
+0

E:无法找到包ncftpput 这是Ubuntu的Linux btw呃看起来像你的意思ncftp? – ablueman

+0

这工作就像一个魅力'ncftpput -u用户-p传递webspace.co.uk/remotefiletostorein//本地/文件/ tostore.php' – ablueman

0

万一有人有兴趣在这里完成的脚本。它所做的只是连接到一个简单的PHP脚本来确定我的远程IP。 (这是每隔几分钟由一个cron工作完成的)。它将它找到的IP与上次存储IP地址的文件进行比较。如果它改变了它将IP保存在比较文件“file1.txt”中并且FTP将该文件保存到ISP托管的web空间中。然后,我可以使用IP作为重定向页面的变量,或者只是检查我最近的IP。

#!/bin/bash 
# Check IP address compare to see if its changed. 
# Save the file to a couple of different places locally 
# FTP the file to regular hosting. 
# File to keep IP address in 
IP_FILE=file1.txt 
echo "File to store and compare IP:" $IP_FILE 
# wget to check current IP address. 
IPADDRESS=$(wget URL/ip.php -O - -q) 
echo "New IP:" $IPADDRESS 
# Read the previous IP address from file 
source $IP_FILE 
echo "Old IP:" $OLD_IP 
# Compare the new to the old IP 
if [ "$IPADDRESS" != "$OLD_IP" ] 
then 
    echo "New IP address detected: $IPADDRESS" 
    # Write new address to file 
    `echo "OLD_IP=$IPADDRESS" > $IP_FILE` 

    # FTP File to the appropriate places 
    # Store it locally as well 
    ncftpput -u user -p pass webspace.co.uk /remotefiletostorein/ /local/file/tostore.php 

fi 

请注意我不知道这样做的安全风险,现在它没关系,但请。除非你知道你在做什么,否则不要使用这个,我对此不负任何责任。

但它确实给你一个备份解决方案,动态主机等

相关问题