コード例 #1
0
ファイル: sftp.cpp プロジェクト: MikhailTatsky/SilkJS
/**
 * @function SFTP.unlink
 * 
 * ### Synopsis
 * 
 * var success = SFTP.unlink(handle, path);
 * 
 * Remove a file on the remote host.
 * 
 * @param {object} handle - opaque handle to existing SFTP connection (already connected).
 * @param {string} path - path to file on remote server to remove.
 * @returns {boolean} success - true if directory was removed.
 */
JSVAL sftp_unlink (JSARGS args) {
    HandleScope scope;
    SFTP *handle = HANDLE(args[0]);
    String::Utf8Value path(args[1]);
    if (libssh2_sftp_unlink(handle->sftp_session, *path)) {
        return scope.Close(String::New("Could not remove file"));
    }
    return scope.Close(True());
}
コード例 #2
0
/* sftp删除文件 */
static int sftp_rm_file(protocol_data_t *protocol, char *filename)
{
    if (protocol == NULL || protocol->protocol_data == NULL 
            || filename == NULL) {
        return -1;
    }
    
    sftp_data_t *data = (sftp_data_t *)protocol->protocol_data;

    return libssh2_sftp_unlink(data->sftp_session, filename);
}
コード例 #3
0
/* sftp删除文件夹 */
static int sftp_rm_dir(protocol_data_t *protocol, char *dirname)
{
    int rc;
    LIBSSH2_SFTP_ATTRIBUTES attrs;
    LIBSSH2_SFTP_HANDLE *dir_handle;
    char source[MAX_PATH_LEN] = {0};

    if (protocol == NULL || protocol->protocol_data == NULL 
            || dirname == NULL) {
        return -1;
    }
    
    sftp_data_t *data = (sftp_data_t *)protocol->protocol_data;
    strcpy(source, dirname);

    dir_handle = libssh2_sftp_opendir(data->sftp_session, source);
    if (!dir_handle) {
        return -1;
    }

    do {
         char filename[MAX_FILENAME_LEN] = {0}; /*255是文件名最大长度*/
         rc = libssh2_sftp_readdir_ex(dir_handle, filename, sizeof(filename), NULL, 0, &attrs);
         if(rc > 0) {
             if (filename[0] != '\0' && filename[0] != '.') {/*略去隐藏文件*/
                 if (LIBSSH2_SFTP_S_ISREG(attrs.permissions)) {
                     add_lastfilename(source, filename);
                     libssh2_sftp_unlink(data->sftp_session, source);
                     del_lastfilename(source);
                 }
                 if(LIBSSH2_SFTP_S_ISDIR(attrs.permissions)){
                     add_lastdirname(source, filename);
                     sftp_rm_dir(protocol, source);
                     del_lastdirname(source);
                 }
             }
         } else if (rc == 0) {
             break;
         } else {
             continue;
         }
    } while (1);

    libssh2_sftp_closedir(dir_handle);
    libssh2_sftp_rmdir(data->sftp_session, source);

    return 0;
}
コード例 #4
0
ファイル: sftpfileengine.cpp プロジェクト: komh/kfw
bool SFtpFileEngine::remove()
{
    qDebug() << "remove()" << _fileName;

    if (!sftpConnect())
        return false;

    bool result = !libssh2_sftp_unlink(_sftp_session,
                                       _textCodec->fromUnicode(_path).data());

    if (result)
    {
        // remove cache entry
        _fileInfoCache->removeFileInfo(getCachePath(_path));
        _fileFlags = QAbstractFileEngine::FileType;
    }

    sftpDisconnect();

    return result;
}
コード例 #5
0
int FSSftp::Delete   ( FSPath& path, int* err, FSCInfo* info )
{
	MutexLock lock( &mutex );
	int ret = CheckSession( err, info );

	if ( ret ) { return ret; }

	try
	{
		int ret;
		WHILE_EAGAIN_( ret, libssh2_sftp_unlink( sftpSession, ( char* )path.GetString( _operParam.charset, '/' ) ) );
		CheckSFTP( ret );
	}
	catch ( int e )
	{
		if ( err ) { *err = e; }

		return ( e == -2 ) ? -2 : -1;
	}

	return 0;
}