25

How can I run this on linux command line when my username has an @ sign in the middle?

ftp -u user:password@host/destination_folder/ sourcefile.txt

My username is info@domain.com and it thinks my host is domain.com.

NOTE: This is an unattended upload, so I can't just type in the username and password.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
bentford
  • 33,038
  • 7
  • 61
  • 57

7 Answers7

25

Try this: use "%40" in place of the "@"

Angus S-F
  • 251
  • 3
  • 2
22

As an alternative, if you don't want to create config files (or you don't want to rely on the behavior of the system-specific ftp command), do the unattended upload with curl instead of ftp:

curl -u user:password -T file ftp://server/dir/file

If you don't want ps (process list) to show the password passed to curl for security reasons, see answers to this question.

pts
  • 80,836
  • 20
  • 110
  • 183
  • 11
    -1 not because it is wrong, but it does not help him with his problem - just gives an alternative. If it is not impossible to do what he wants with what he wants, why should he change the tool? – Oliver Friedrich Jan 11 '10 at 10:18
  • @OliverFriedrich: One possible reason to change the tool is right in the first paragraph in the answer: *if you don't want to create config files*. Creating and maintaining config files is a mental burden, and it can also be a key storage security issue, because then a password is saved to disk. Another possible reason to change the tool is that the arguments of the *ftp* command vary from system to system, and *curl* is more portable. – pts Apr 15 '23 at 09:13
  • @OliverFriedrich: The problem of the OP is not obvious from the question (it may be an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)): maybe they want to use the *ftp* command, maybe they want to do unattended uploads to an FTP server, using any tool. My answer fits the latter, other answers fit the former. – pts Apr 15 '23 at 09:24
12

Try to define the account in a ~/.netrc file like this:

machine host login info@domain.com password mypassword

Check man netrc for details.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
moinudin
  • 134,091
  • 45
  • 190
  • 216
6

I simply type ftp hostdomain.com and the very next prompt asked me to enter a name, if it wasn't the same as my current user.

I guess it depends on how your FTP is configured. That is, whether it assumes the same username (if not provided) or asks. the good news is that even without a solution, next time you face this it might Just Work™ for you :D

Zearin
  • 1,474
  • 2
  • 17
  • 36
innovati
  • 527
  • 1
  • 8
  • 12
2

A more complete answer would be it is not possible with ftp(at least the ftp program installed on centos 6).

Since you wanted an un-attended process, "pts"'s answer will work fine.

Do the unattended upload with curl instead of ftp:

curl -u user:password -T file ftp://server/dir/file

%40 doesn't appear to work.

[~]# ftp domain.com
ftp: connect: Connection refused
ftp> quit
[~]# ftp some_user%40domain.com@domain.com
ftp: some_user%40domain.com@domain.com: Name or service not known
ftp> quit

All I've got is to open the ftp program and use the domain and enter the user when asked. Usually, a password is required anyway, so the interactive nature probably isn't problematic.

[~]# ftp domain.com
Connected to domain.com (173.254.13.235).
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 1000 allowed.
220-Local time is now 02: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 (domain.com:user): some_user@domain.com
331 User some_user@domain.com OK. Password required
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
Stephen
  • 1,603
  • 16
  • 19
1

curl -f -s --disable-epsv -u someone@somewhere.com:gr8p455w0rd -T /some/dir/filename ftp://somewher.com/ByramHealthcareCenters/byram06-2011.csv

-3

I've never seen the -u parameter. But if you want to use an "@", how about stating it as "\@"?

That way it should be interpreted as you intend. You know something like

ftp -u user\@domain.tld@ftp.host.tld
Stephan
  • 41,764
  • 65
  • 238
  • 329
Sal
  • 1
  • 3
    Can't use \@. The shell will interpret the \@ as a plain @ and process it before the ftp command ever sees it. You have to use %40 (hex/ascii for @) which the shell will ignore and the ftp command will interpret as @. – Wes Miller Apr 16 '12 at 12:32
  • 1
    If you have never seen -u parameter (and obviously have never tested it) why you suggest to use it? – Kornel Jan 10 '16 at 09:55