creating directory in ftp server using ncftp command from ubuntu terminal

6,561

Solution 1

When using ncftp you should have the ability to create directories at both a local and remote location:

  1. lmkdir This command creates directories on the local host
  2. mkdir This command creates directories on the remote host

Bear in mind that you will need suitable permission on the remote host to create any directories.

Below is an example on my own ftp server, I have obscured the username and password and added in a few arrows:

andrew@corinth:~$ ncftp ftp://username:[email protected]/andrews-corner.org/test/
NcFTP 3.2.5 (Feb 02, 2011) by Mike Gleason (http://www.NcFTP.com/contact/).
Connecting to 208.113.217.97...
DreamHost FTP Server
Logging in...
User username logged in
Logged in to andrews-corner.org.                                
Current remote directory is /andrews-corner.org/test.
ncftp /andrews-corner.org/test > mkdir hello_sysadminboy                      <-----
ncftp /andrews-corner.org/test > dir                                          <-----
drwxr-xr-x   14709624 227249                Sep 12 12:50   hello_sysadminboy  <-----
ncftp /andrews-corner.org/test > quit
andrew@corinth:~$

You can see from the above that I have:

  1. Successfully logged in and automatically changed to a test directory
  2. Created the remote directory 'hello_sysadminboy'
  3. Tested the directory with the dir command

If you wanted to script this sort of thing something like the following works well on my system:

#!/bin/sh

ncftp ftp://username:[email protected]/andrews-corner.org/test/<<EOF
mkdir hello_sysadminboy
dir
EOF

Unfortunately the mkdir -p command does not work remotely to create nested directories and brace expansion is ignored...

Solution 2

Use the -m switch:

ncftpput -u <USERNAME> -p <PASSWORD> -P <PORT> -m noc.netmihan.com /REMOTE_DIR LOCAL_DIR/example.txt

Look at the ncftp documentation for more info.

Share:
6,561

Related videos on Youtube

sysadminboy
Author by

sysadminboy

Updated on September 18, 2022

Comments

  • sysadminboy
    sysadminboy almost 2 years

    How to create a directory in a specific path in Ftp server by using Ncftp command from Ubuntu terminal. Is it possible?

  • sysadminboy
    sysadminboy almost 8 years
    i have tried it but it only provides login to ftp server directory is not created can you please provide the syntax?
  • andrew.46
    andrew.46 almost 8 years
    @sysadminboy I have added an example from my own ftp server
  • sysadminboy
    sysadminboy almost 8 years
    it is for a script to automatcially create directory ..here you have done it manually
  • andrew.46
    andrew.46 almost 8 years
    @sysadminboy OK so I have added in a scripting example. Note that I have used a shorthand method for username and password. I am not aware of a method to accomplish this with a single command unfortunately...
  • andrew.46
    andrew.46 almost 8 years
    @sysadminboy That is excellent news! And have a good day :)
  • sysadminboy
    sysadminboy almost 8 years
    is it possible to monitor a directory in ncftp server and if new files appear in that directory i need to copy it to my local system with ncftpget(something like watchfolder).
  • andrew.46
    andrew.46 almost 8 years
    @sysadminboy I am not sure... This might be better as a new question?
  • sysadminboy
    sysadminboy almost 8 years
    askubuntu.com/questions/830570/… . here is the qwestion please help me. Thanks
  • sysadminboy
    sysadminboy over 7 years
    ssh [email protected]<<EOF inotifywait -m /tmp/sample/ -e create -e moved_to | while read path action file; do echo "new file found" #scp -r /tmp/sample/ [email protected]:/tmp/ done EOF ... by doing so i am able to get notification when a new file occurs but how to copy it to my system using ncftpget because every time a new file appears it has to be copied using ncftpget to my system ..is it possible.
  • sysadminboy
    sysadminboy over 7 years
    askubuntu.com/questions/830570/… ..here is that qwestion. please help.