bool SFtpFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const { Q_UNUSED(recurseParentDirectories); qDebug() << "rmdir()" << _fileName << dirName; SFtpFileEngine* This(const_cast<SFtpFileEngine*>(this)); if (!This->sftpConnect()) return false; QUrl url(PathComp::fixUrl(dirName)); bool result = !libssh2_sftp_rmdir(_sftp_session, _textCodec->fromUnicode( url.path()).data()); if (result) { // remove cache entry This->_fileInfoCache->removeFileInfo(This->getCachePath(url.path())); if (_path == url.path()) This->_fileFlags = QAbstractFileEngine::FileType; } This->sftpDisconnect(); return result; }
/** * @function SFTP.rmdir * * ### Synopsis * * var success = SFTP.rmdir(handle, path); * * Remove a directory on the remote host. * * @param {object} handle - opaque handle to existing SFTP connection (already connected). * @param {string} path - path on remote server to remove. * @returns {boolean} success - true if directory was removed. */ JSVAL sftp_rmdir (JSARGS args) { HandleScope scope; SFTP *handle = HANDLE(args[0]); String::Utf8Value path(args[1]); if (libssh2_sftp_rmdir(handle->sftp_session, *path)) { return scope.Close(String::New("Could not remove directory")); } return scope.Close(True()); }
/* 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; }
int FSSftp::RmDir ( 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_rmdir( sftpSession, ( char* )path.GetString( _operParam.charset, '/' ) ) ); CheckSFTP( ret ); } catch ( int e ) { if ( err ) { *err = e; } return ( e == -2 ) ? -2 : -1; } return 0; }