Wie lade ich eine Datei per FTP von der Befehlszeile hoch?

Ich muss eine einzelne Datei von Ubuntu auf den FTP-Server hochladen. Dieser Vorgang sollte in einem Skript (im nicht interaktiven Modus) ausgeführt werden. Was ist die richtige Syntax für ftp?

Ich versuche das ohne Erfolg:

$ ftp -u ftp://user:[email protected] my-local-file.txt
ftp: Invalid URL `ftp://'
Author: yegor256, 2011-08-15

10 answers

Hier ist ein Ansatz:

$ ftp -n <<EOF
open ftp.example.com
user user secret
put my-local-file.txt
EOF

Alternativ erstellen (oder bearbeiten)Sie das~/.netrc-Datei im Home-Verzeichnis des Benutzers, der den ftp-Befehl ausführt, geben Sie ihm die entsprechenden perms (chmod 0600 ~/.netrc) und fügen Sie Folgendes hinzu:

# ~/.netrc
machine ftp.example.com
login user
password secret

Dann lassen Sie die Login-Informationen, wie in:

$ echo put my-local-file.txt | ftp ftp.example.com

Auch hier ist, wie Sie das gleiche mit curl tun könnten:

$ curl -T my-local-file.txt ftp://ftp.example.com --user user:secret
 211
Author: Marty,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-08-15 05:13:17

Ich kann ftp-upload empfehlen. Es ist ein nettes kleines Tool, das Sie unter Ubuntu über sudo apt-get install ftp-upload installieren können.

Verwendungsbeispiel:

ftp-upload -h {HOST} -u {USERNAME} --password {PASSWORD} -d {SERVER_DIRECTORY} {FILE_TO_UPLOAD}
 19
Author: Floris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-01-27 15:52:13

Sie müssen die in Ihrer Anweisung angegebene URL korrigieren. Sie haben den Fehler erhalten, weil die URL unvollständig war - es fehlte der Name des Objekts, das Sie hochladen. Sobald Sie den Dateinamen nach 'hinzufügen example.com" wie ich unten ausgeführt habe, werden Sie sehen, dass der einzelne Befehl tatsächlich so funktioniert, wie Sie es beabsichtigt haben.

Versuche das:

ftp -u ftp://user:[email protected]/my-local-file.txt my-local-file.txt

 5
Author: Paul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-12-12 19:11:24

Sie können auch versuchen lftp.

Hier ist ein Beispiel:

lftp -e 'cd folder1/folder2; put /home/path/yourfile.tar; bye' -u user,password ftp.theserver.com

Siehe hier für weitere Details und siehe auch LFTP Manual

.

 5
Author: divinedragon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2021-02-04 15:43:24

Ncftp Installieren und verwenden Sie das ncftpput - tool, das zusammen mit ihm kommt, ziemlich viel, so etwas wie diese syntax:

ncftpput -u ftpuser -p ftppass ftphostname /path/where/to/upload localfile.name
if [ $? -ne 0 ]; then echo "Upload failed"; fi

Sie können sogar überprüfen, ob der Upload-Status gut oder schlecht ist. Der normale FTP-Client kann auch zusammen mit expect verwendet werden.

 4
Author: O G,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2013-11-27 10:53:23

Laden Sie eine Datei über die Befehlszeile an einen entfernten Speicherort hoch

#!/bin/bash
#$1 is the file name
#usage:this_script <filename>
HOST='yourhost'
USER="youruser"
PASSWD="pass"
FILE="abc.php"
REMOTEPATH='/html'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $REMOTEPATH
put $FILE 
quit
END_SCRIPT
exit 0
 2
Author: Shal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-04-29 09:16:12

Ich benutze BusyBox ' s ftpput, um dies zu tun:

# /bin/busybox ftpput

BusyBox v1.20.2 (Debian 1:1.20.0-7) multi-call binary.

Usage: ftpput [OPTIONS] HOST [REMOTE_FILE] LOCAL_FILE

Upload a file to a FTP server

    -v,--verbose            Verbose
    -u,--username USER      Username
    -p,--password PASS      Password
    -P,--port NUM           Port

Hinweis: busybox ftpget funktioniert auch gut.

 1
Author: Naskel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-03-24 04:17:05

Ich verbesserte Marty Antwort wie folgt (include binary):

[ftp_example_1.sh]

$ ftp_example_sh.sh dump_file

ftp -n <<EOF
open 192.168.0.10
user anonymous aaa
binary
put $1
EOF

[ftp_example_2.sh]

$ftp_example_2.sh 192.168.0.10 dump_file

ftp -n <<EOF
open $1
user anonymous aaa
binary
put $2
EOF
 0
Author: sailfish009,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-07-31 02:59:52

Sie können auch den Befehl sftp oder ftp verwenden

sftp {user}@{IP}
Password:
put {path To File On Local Computer}

 -1
Author: iProgram,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-02-16 19:37:53
FtpPut(){
    echo `echo -e "open host\nuser user pass\nbinary\nput $1\nquit"|ftp -nv`
}
FtpPut asd.txt
FtpPut asd.mp4
FtpPut asd.php
...
 -1
Author: Yöncü Bilişim Çözümleri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-08-25 18:06:21