mkdir -p option in SFTP session


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mkdir -p option in SFTP session
# 1  
Old 09-27-2012
mkdir -p option in SFTP session

Hi,

I am trying to create more than one directory by using -p option in SFTP session.
But it created a directory named -p and ended.

It didn't throw any error.
Code:
sxxxxxxx:(abc)/test> sftp abcuser@zxxxxxxx
Connecting to zxxxxxxx...
Password:
sftp> pwd
Remote working directory: /test
sftp> cd /test/test1/test2/test3
sftp> mkdir -p /test/test1/test2/test3/test4/test5/test6/test7
sftp> bye


zxxxxxxx:(abc)/test/test1/test2/test3> ls
-p
zxxxxxxx:(abc)/test/test1/test2/test3> ls -lrt
total 0
drwxr-xr-x   2 abcuser users         96 Sep 27 10:09 -p

I will get that directory at run time from the user.

Please let me know how to create more than one directories using single commad in SFTP session.

Regards,
gthangavSmilie



Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by vbe; 09-27-2012 at 11:50 AM..
# 2  
Old 09-27-2012
Not sure -p is a valid option for mkdir in sftp... which explains what happened...
sftp is quite dumb you know... its not like an ordinary remote connetion...all the command it understand are limited in options...
Since yu are using sftp, dont you have ssh? ssh can be used in batch mode...
# 3  
Old 09-27-2012
You could try using the -b (batch) option to sftp. Create a file with the commands:

Code:
cat file

mkdir /tmp/test1
mkdir /tmp/test1/test2
mkdir /tmp/test1/test2/test3
mkdir /tmp/test1/test2/test3/test4

Then just use the -b option to feed it to the sftp command:

Code:
sftp -b file user@server

sftp> mkdir /tmp/test1
sftp> mkdir /tmp/test1/test2
sftp> mkdir /tmp/test1/test2/test3
sftp> mkdir /tmp/test1/test2/test3/test4

Then verify on the server:

Code:
ls -l /tmp/test1/test2/test3/test4/

A bit funky, but should work if you insist on using sftp.

Alternatively, you could just use the ssh command like so:

Code:
ssh user@server 'mkdir -p /tmp/test1/test2/test3/test4/'

# 4  
Old 09-27-2012
sftp is not a shell, it probably won't understand most or any of the usual commandline flags. if you need a shell, use ssh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

SFTP with limit(l) option

Hi, I have sftp installed in some of my corporate servers (test and production). However, I notice that it does not have the limit(l) option for bandwidth limit option. Why is this? Is it because sftp was not installed with other necessary packages? How do I make sftp available with the... (4 Replies)
Discussion started by: anaigini45
4 Replies

2. UNIX for Advanced & Expert Users

Error while renaming the file in SFTP Session

Hi All Below is the script I am trying to execute to rename a file in an SFTP session. It is in GNU/Linux. This script is for generic use and so I am passing arguments. Everything in the script works fine except "reading the filename in SFTP session" In the below script the... (2 Replies)
Discussion started by: sparks
2 Replies

3. Shell Programming and Scripting

What is -oStrictHostKeyChecking option in SFTP Command?

Can anyone explain me the below sftp command sftp -oStrictHostKeyChecking=no @SFTP_PROXY_COMMAND@ -v oIdentityFile=$sftpIdentity -b $PutSFTPbatch.bat $sftpUrl I need explanation for the below parameters with all their possible values -oStrictHostKeyChecking=no @SFTP_PROXY_COMMAND@ -v... (1 Reply)
Discussion started by: Little
1 Replies

4. Shell Programming and Scripting

i want to execute shell script on remote server with in sftp session

Hi, I want to execute shell script with in sftp session for remote server. like i have a shell script test.sh that is on local server.i want to execute that script on remote server sftp user@192.168.56.10 sftp> test.sh ---execute for remote server not for local server. sftp... (3 Replies)
Discussion started by: SAUD PASHA
3 Replies

5. Shell Programming and Scripting

Passwordless SFTP - SCP Option?

I have read documentation on SCP and just trying to figure out how go about doing this - below are two pieces of code, one is SFTP and one is SCP. My goal is to have this done via password-less authentication, fully automated. Currently we use SFTP and the script asks for the password of the... (20 Replies)
Discussion started by: Stigy
20 Replies

6. Shell Programming and Scripting

sftp -b option

Hi, what does -b option do in sftp batch mode..?:confused: (1 Reply)
Discussion started by: rahulsxn660
1 Replies

7. Shell Programming and Scripting

Execute shell script within sftp session

Hi all , can any one tell me how to run a script within a sftp session. let me tell u in bit clear way : After I connected to sftp location , cd ing to some directory then I need to execute a one script. Please tell me if u have any idea on this . Looking forward to your reply guys... (1 Reply)
Discussion started by: sravan008
1 Replies

8. Shell Programming and Scripting

Catch error from SFTP session

We have script running to SFTP some file to the remote server. The problem is the SFTP transfer returns an exit code of 0 even if there is permission error during file transfer, connection refuse (like when sftp server is down), thus, returning the status of the script as success. I was thinking... (3 Replies)
Discussion started by: The One
3 Replies

9. UNIX for Advanced & Expert Users

SFTP - Overwrite [Put -P <file>] option

Hi All Experts, I hope you are all ok! :D My question is simple but I was not able to find an answer in the internet, and that's why I am here! My question is: when I sftp to a server and use "put -P" option to put a file, it keeps the file's full permission and access time. Check below... (5 Replies)
Discussion started by: felipe.vinturin
5 Replies

10. UNIX for Advanced & Expert Users

sftp problem with user id of no telnet session allowed

We used to have a ftp user id with no telnet session allowed in server side. We used this ftp user id in script by transferring file from client to Server. Currently we need to implement sftp to replace ftp. We have tested few round and working fine by using sftp with normal user id (allow... (2 Replies)
Discussion started by: superdougl
2 Replies
Login or Register to Ask a Question