Upload folder linux ftp

How to upload one file by FTP from command line?

I need to upload a single file to FTP server from Ubuntu. This operation should be done in a script (in non-interactive mode). What is the right syntax for ftp ? I’m trying this, to no avail:

$ ftp -u ftp://user:secret@ftp.example.com my-local-file.txt ftp: Invalid URL `ftp://' 

I don’t know much about the ftp tool in Ubuntu, but it looks like it’s choking on the ftp:// . try taking that out maybe?

12 Answers 12

Alternatively, create (or edit) the ~/.netrc file in the home dir of the user that will run the ftp command, give it appropriate perms ( chmod 0600 ~/.netrc ), and add the following:

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

Then omit the login information, as in:

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

Also, here’s how you might do the same thing using curl:

$ curl -T my-local-file.txt ftp://ftp.example.com --user user:secret 

FYI: I’ve noticed that I can’t pass a full path of the file using the put raw command but I can with curl .

+1 for the curl. Neat, clean and straight to the point! In Debian/Ubuntu «apt-get install curl», if you don’t have it.

FWIW: I tried this with a large file (162MB). At first I thought curl looked slow (~25mins), but I found that the ftp command took just as long. curl looks good if available, and has nice feedback showing Time Left etc.

For uploads to a specific folder put a slash after the folder name: ftp://ftp.example.com/myFolder/ otherwise youl’ll get «Failed FTP upload: 553»

I can recommend ftp-upload . It’s a neat little tool that you can install under ubuntu through sudo apt-get install ftp-upload .

Читайте также:  Узнать количество папок linux

Hi DragonLord, if you are in Ubuntu and you have installed ftp-upload (using the command I gave before) you can just do man ftp-upload . Hope that helps.

@Xanlantos yes unfortunately it will leave the password in the bash history. I think there are ways around it I found through Google (but I don’t recall exactly).

You need to fix the URL given in your statement. You received the error because the URL was incomplete — it was missing the name of the object you are uploading. Once you add the filename after ‘example.com’ as I have done below, you will see the single command does indeed work as you intended.

perhaps it’s version dependant, like nc -e flag. my ftp command has the -u and following this format, it worked nicely!

Ah I just figured one thing out: this is because my ftp command is, actually, tnftp . You may want to check what FTP client you’re actually using, since they’ll have different capabilities!

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

Refer here for more details and also refer to LFTP Manual

To use it with non unix name I found this: NN=»‘non unix.file'» ; lftp -e «cd folder; put $NN; bye» -u anonymous, ftp.theserver.com

With the example above yes, it will be in the history. You can use the —env-password flag and have the password configured in LFTP_PASSWORD environment variable. Refer to the man pages of LFTP

Install ncftp and use the ncftpput tool that comes along with it, pretty much something like this syntax:

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

You can even check if the upload status is good or bad. The normal ftp client can also be used along with expect.

Читайте также:  Массовое создание пользователей linux

Upload a file to a remote location via command line

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

I use BusyBox's ftpput to do this:

# /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 

Note: busybox ftpget work well too.

Use the put command after connecting to the FTP server with ftp (it is interactive, btw).

put local-file [remote-file] Store a local file on the remote machine. If remote-file is left unspecified, the local file name is used after processing according to any ntrans or nmap settings in naming the remote file. File transfer uses the current settings for type, format, mode, and structure. 
~ $ ftp 127.0.0.1 Connected to 127.0.0.1. 220---------- Welcome to Pure-FTPd [privsep] ---------- 220-You are user number 1 of 25 allowed. 220-Local time is now 10:47. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (127.0.0.1:user1): user2 331 User user2 OK. Password required Password: 230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. 

Example copy (login required before it):

ftp> put index.html local: index.html remote: index.html 200 PORT command successful 150 Connecting to port 43791 226-File successfully transferred 226 0.003 seconds (measured here), 3.96 Mbytes per second 10701 bytes sent in 0.00 secs (34.4773 MB/s) 

Example logout (login required before it)

ftp> quit 221-Goodbye. You uploaded 11 and downloaded 0 kbytes. 221 Logout. ~ $ 

Источник

FTP command to put a directory to server from local system

You can use ncftp software to put directory tree from local to ftp servers. You need to install this ftp software.

a transfer all files in ASCII mode and not in binary.

v to see output in verbose mode

R to copy folders in recursive mode.

ftp can't put directly directory trees, only files.

If you have sshd on the remote system, you can probably use rsync .

It has built-in compression and all sorts of other goodness:

% rsync -chavz --partial --progress --stats test remotehost: sending incremental file list test/ test/test.c 387 100% 0.00kB/s 0:00:00 (xfer#1, to-check=5/7) test/test.cpp 231 100% 225.59kB/s 0:00:00 (xfer#2, to-check=4/7) test/test.new 253 100% 123.54kB/s 0:00:00 (xfer#3, to-check=3/7) test/test.php 578 100% 282.23kB/s 0:00:00 (xfer#4, to-check=2/7) test/test.py 288 100% 140.62kB/s 0:00:00 (xfer#5, to-check=1/7) test/test.sh 81 100% 26.37kB/s 0:00:00 (xfer#6, to-check=0/7) Number of files: 7 Number of files transferred: 6 Total file size: 1.82K bytes Total transferred file size: 1.82K bytes Literal data: 1.82K bytes Matched data: 0 bytes File list size: 193 File list generation time: 0.003 seconds File list transfer time: 0.000 seconds Total bytes sent: 1.54K Total bytes received: 130 sent 1.54K bytes received 130 bytes 159.43 bytes/sec total size is 1.82K speedup is 1.09 

Watch what happens if you run it again and no files have changed.

% rsync -chavz --partial --progress --stats test remotehost: sending incremental file list Number of files: 7 Number of files transferred: 0 Total file size: 1.82K bytes Total transferred file size: 0 bytes Literal data: 0 bytes Matched data: 0 bytes File list size: 193 File list generation time: 0.003 seconds File list transfer time: 0.000 seconds Total bytes sent: 207 Total bytes received: 13 sent 207 bytes received 13 bytes 23.16 bytes/sec total size is 1.82K speedup is 8.26 

Источник

Оцените статью
Adblock
detector