5

I want to send some specific files from my linux PC to my android device. I'd like to send it automatically using terminal commands, so there will be no drag and drop files.

I don't know what is the best communication way to send file via wifi. I understand how to send using ftp by downloading 'ftp server' app on my android, but that's not suitable to my work since it needs to open an internet browser on my PC and transfer like a file manager. So I tried using ssh:

scp /home/user/picture1.jpg [email protected]:/storage/emulated/0

but always ended up error:

ssh: connect to host 192.168.1.117 port 22: Connection refused
lost connection

How to solve this problem? or does anyone have any other recommendation which communication way should I use?

1

4 Answers 4

2

You have different options here:

  • SCP: As Dan already pointed out, Android soesn't ship with any SSH server by default. This means, to use SCP as described in your question, you will first have to install an SSH Server App on your device.
  • FTP: Other than you're assuming in your question, FTP can be scripted. But that might not come as easy as a simple scp command. And like with SSH, you first will need to install an FTP Server App on your device as well.
    Important note: Many FTP clients/connections default to ASCII transfer mode. If you want to copy binary (basically: non-text) files like images, audio/video, etc., make sure you're in binary mode (when using the command-line, that can be done by issuing the bin command). Otherwise you might get "broken files" on the receiving end.
  • ADB: This is an option Android even ships with, but by default bound to an USB connection. You'd just need to enable USB Debugging in developer settings, connect your device via USB, and then can use commands like adb push or adb pull to put files on your device or retrieve them from there. As you prefer doing that via WiFi, there are several apps providing this as well.

There might be additional possiblities, but the three mentioned above are the most used.

6
  • Thanks for your answer. I successfully connected my android phone in ftp connection. When I executed command: put /home/user/picture.jpg the result is 551 /home/user/picture.jpg: error on output file
    – user19
    May 15, 2014 at 13:27
  • Sorry, but I cannot help you with that. Maybe you make this a new question, and also include details on what FTP server you are using, and the exact sequence of commands? I can only guess you might have no write permission on the target folder, or there's not enough space available (but that should give different error codes). The list of ftp server return codes says for 551: Page type unknown. No idea what's that meant to be.
    – Izzy
    May 15, 2014 at 14:53
  • Update: I didn't know what have I changed, but when I tried again the ftp command finally works! The image file successfully sent but the image is broken. I don't know why. Thank you for help @Izzy. anyway I'm still curious why the ssh communcication does not work.
    – user19
    May 15, 2014 at 15:19
  • Hm, you've used FTP for transfer? Sure you set the transfer mode to BINary? By default, FTP often uses ASCii mode (before the put ..., execute a bin to ensure you're in binary mode) – which perfectly would explain the "broke".
    – Izzy
    May 15, 2014 at 16:04
  • Thank you for your information! I didn't know that. Now It works perfectly.
    – user19
    May 15, 2014 at 16:23
0

You can use scp if you like, but you first have to install a SSH server on the phone. Android doesn't come with one enabled by default: that would be a security nightmare. There are many to choose from on Google Play.

3
  • Thank you for your answer. I downloaded 'ssh server' on my android. I start by adding server, set server name and port. I also checked enable scp option. and lastly start server. I executed command: scp /home/user/picture1.jpg a[email protected]:48503:/storage/sdcard0/Download but connection still refused. Did I make mistake on my command?
    – user19
    May 15, 2014 at 11:04
  • My first suggestion would be to ping the phone, in order to check the IP address is right and the Wi-Fi router isn't blocking the connection.
    – Dan Hulme
    May 15, 2014 at 11:54
  • PING 192.168.1.105 (192.168.1.105) 56(84) bytes of data. --- 192.168.1.105 ping statistics --- 10 packets transmitted, 9 received, 10% packet loss, time 9011ms. The phone is connected
    – user19
    May 15, 2014 at 12:42
0

If you are on the same wi-fi network as your mobile phone is and you have got the option to use ADB I would recommend using wireless adb. Setup wireless ADB on your phone and ADB on your PC. Then just hit

adb connect <Local IP of your phone>

And when the device is connected you can use

adb push /path/local/file /path/remote/location/

1
  • Thank you for your answer. I am currently downloading androidSDK, so it may take quite a long time before I can test using adb.
    – user19
    May 15, 2014 at 11:25
0

If you are using Wifi,

Through ESFileExplorer, you can create a FTP Server for your Mac or Unix File System and copy files on the fly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .