Sponsored Content
Full Discussion: SFTP Does directory exist?
Top Forums Shell Programming and Scripting SFTP Does directory exist? Post 302556965 by ahamed101 on Tuesday 20th of September 2011 07:58:31 AM
Old 09-20-2011
I don't think we can do that within sftp. Only basic commands like ls works.
But since you have sftp set up, you can make use of ssh to check the directory existence and then proceed with sftp
Code:
ret=$( ssh ${SFTP_ACCOUNT}@${SFTP_ADDR} "test -d $SFTP_DESTINATION >/dev/null 2>&1; echo \$?" )
 
if [ $ret -eq 0 ]
then
  echo "Now go ahead with sftp"
fi

--ahamed

Last edited by ahamed101; 09-20-2011 at 09:17 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

how to check if directory/file exist using c/c++

Hi there, how to check if directory/file exist using c/c++ under linux/unix. Thanks. Steven (2 Replies)
Discussion started by: steven88
2 Replies

2. Shell Programming and Scripting

How to check directory exist on servers

There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script. #! /bin/ksh ARRAY_DIRECTORIES="/c/dev/custom/bin" ARRAY_DIRECTORIES="/c/dev/db/custom/src" ARRAY_ENV="remoteName200" ARRAY_ENV="remoteName201"... (2 Replies)
Discussion started by: weonpc
2 Replies

3. Shell Programming and Scripting

To check whether a directory is exist and if it is not, create it

Hi, I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies

4. Shell Programming and Scripting

check the directory exist

I have the below script to check whether directory is exist or not , now I sure the directory /abc NOT exist , but when run the script , it still pop the result is "the directory exist" , could suggest what is wrong ? thx ll -d /abc > /dev/null 2>&1 if then echo "the directory exist !!" ... (7 Replies)
Discussion started by: ust
7 Replies

5. Shell Programming and Scripting

sftp mget where file doesn't exist BASH

I have a script that is working: #!/bin/bash sftp user@domain.com <<EOF cd somedir mget *.csv quit EOF but on a crontab I want to only pull newer files, so I want to do something like: while read ls current dir local file != true do mget that new file but I'm not sure the syntax... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. UNIX for Advanced & Expert Users

Directory is invisible in listing but it is exist.

Hi ALL. Can anyone could help me. Have you had a chance to experienced that when you list (ls) a directory from ordinary execution of command, you couldn't see the directory. However, when you list it from the directory filename itself or even changing to directory (cd), it will show to you... (9 Replies)
Discussion started by: BCJapan
9 Replies

7. Shell Programming and Scripting

how to check file exist in a directory or not

HI folks, can any one tell me how to check whether the file is existed in a directory or not . let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail .. i have the mail logic .. but I'm failed to check file existence .. please... (5 Replies)
Discussion started by: sravan008
5 Replies

8. Solaris

User directory doesn't exist

Hii all, i create the user useradd -d /home/kk kk passwd kk when i tried to login to kk i get a error user directory doesn't exist then i tried useradd kkk passwd kkkwhen i tried to login to kkk i get the same error user directory doesn't exist. (4 Replies)
Discussion started by: vipinkumarr89
4 Replies

9. UNIX for Beginners Questions & Answers

A file or directory in the path does not exist

I'm brand new to AIX and I looked up how to print this file and it was working but now I'm not able to do it all of a sudden. the file name is rom1.txt so this is what i wrote in the command line and I know I'm in the right directory. In bold is what I seem to be messing up with. prod @ root... (3 Replies)
Discussion started by: Dark0Prince
3 Replies

10. UNIX for Beginners Questions & Answers

Linux sftp — how to add new user to access exist directory with write permission?

I have built a website and I can access and edit the website'files on server via the root user. The current file and directory structures are not changeable. Now I am hiring a webpage designer to help me re-design some pages, I am going to let the designer edit the files directly on the server. So... (5 Replies)
Discussion started by: uwo-g-xw
5 Replies
libssh2_sftp_open_ex(3) 					  libssh2 manual					   libssh2_sftp_open_ex(3)

NAME
libssh2_sftp_open - open filehandle for file on SFTP. SYNOPSIS
#include <libssh2.h> #include <libssh2_sftp.h> LIBSSH2_SFTP_HANDLE * libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len, unsigned long flags, long mode, int open_type); DESCRIPTION
sftp - SFTP instance as returned by libssh2_sftp_init(3) filename - Remote file/directory resource to open filename_len - Length of filename flags - Any reasonable combination of the LIBSSH2_FXF_* constants: LIBSSH2_FXF_READ Open the file for reading. LIBSSH2_FXF_WRITE Open the file for writing. If both this and LIBSSH2_FXF_READ are specified, the file is opened for both reading and writing. LIBSSH2_FXF_APPEND Force all writes to append data at the end of the file. LIBSSH2_FXF_CREAT, If this flag is specified, then a new file will be created if one does not already exist (if LIBSSH2_FXF_TRUNC is specified, the new file will be truncated to zero length if it previously exists) LIBSSH2_FXF_TRUNC Forces an existing file with the same name to be truncated to zero length when creating a file by specifying LIB- SSH2_FXF_CREAT. LIBSSH2_FXF_CREAT MUST also be specified if this flag is used. LIBSSH2_FXF_EXCL Causes the request to fail if the named file already exists. LIBSSH2_FXF_CREAT MUST also be specified if this flag is used. mode - POSIX file permissions to assign if the file is being newly created. See the LIBSSH2_SFTP_S_* convenience defines in <lib- ssh2_sftp.h> open_type - Either of LIBSSH2_SFTP_OPENFILE (to open a file) or LIBSSH2_SFTP_OPENDIR (to open a directory). RETURN VALUE
A pointer to the newly created LIBSSH2_SFTP_HANDLE instance or NULL on failure. ERRORS
LIBSSH2_ERROR_ALLOC - An internal memory allocation call failed. LIBSSH2_ERROR_SOCKET_SEND - Unable to send data on socket. LIBSSH2_ERROR_SOCKET_TIMEOUT - LIBSSH2_ERROR_SFTP_PROTOCOL - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. LIBSSH2_ERROR_EAGAIN - Marked for non-blocking I/O but the call would block. SEE ALSO
libssh2_sftp_close_handle(3) libssh2 0.15 1 Jun 2007 libssh2_sftp_open_ex(3)
All times are GMT -4. The time now is 12:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy