videolabs/libdsm

smb_file_mv seems not working

Opened this issue · 15 comments

Hi,
I'm trying to use your lib in my ios project
But have some troubles with move operation.

My code example:

smb_session *session = smb_session_new();
smb_session_connect(session, hostName, addr.s_addr, SMB_TRANSPORT_TCP);
smb_session_set_creds(session, hostName, userName, password);

smb_tid treeID;
NSString *shareName = [self.path shareName];
const char *shareCString = [shareName cStringUsingEncoding:NSUTF8StringEncoding];
smb_tree_connect(self.smbSession, shareCString, &treeID);

NSString *srcPath = [self.path formattedFilePath];  // path like "\\myfolder\\\\file.txt"
NSString *dstPath = [[dst stringByTrimmingCharactersInSet:trimSet] slashesEscape]; // "\\mysharename\\\\myfolder\\\\file2.txt"
    
int result = smb_file_mv(self.smbSession,self.treeID,srcPath.UTF8String,dstPath.UTF8String);

and now I got "result == -3"

Maybe I'm doing something wrong?

Other operations like create folder or remove works perfectly.

Hi,
"\mysharename\\myfolder\\file2.txt" -> Why are you having a share name in the path ? SMB is not allowing files to be moved from a share to another share so you should't have it in the dest path.

I've tried different variations =)
This was last

This not working too

\\myfolder\\\\file2.txt

Hi,
Is any news?

Hi, have you solved this issue? We face the same problem :(

It should not be hard to fix, tbh.

Ah, interesting.

I fail to reproduce the issue.

For future reference here is the sample I used

#include <bdsm/netbios_ns.h>
#include <bdsm/netbios_defs.h>
#include <bdsm/smb_session.h>
#include <bdsm/smb_types.h>
#include <bdsm/smb_share.h>

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define FOLDER "\\madamemichu\\Documents\\SharedLoutre\\"

int main()
{
    struct sockaddr_in addr;
    const char* host = "hydromel";
    const char* user = "MadameMichu";
    const char* pass = "loutre";
         

    netbios_ns* ns = netbios_ns_new();
    if (netbios_ns_resolve(ns, host, NETBIOS_FILESERVER, &addr.sin_addr.s_addr) != 0)
    {
        printf("Failed to resolve host\n");
        exit(2);
    }

    smb_session *session = smb_session_new();
    if (smb_session_connect(session, host, addr.sin_addr.s_addr, SMB_TRANSPORT_TCP) != 0)
    {
        printf("Failed to create session\n");
        exit(3);
    }
                 
    smb_session_set_creds(session, host, user, pass);
    if (smb_session_login(session) != 0)
    {
        printf("failed to login\n");
        exit(1);
    }

    smb_tid tid;
    if ( smb_tree_connect(session, "Users", &tid) != 0)
    {
        printf("failed to list folder\n");
        exit(1);
    }

    if (smb_file_mv(session, tid, FOLDER "loutre.txt", FOLDER "newLoutre.txt" ) != 0)
    {
        printf("Failed to move file\n");
        exit(123);
    }
}

I have not tried this myself but the examples above as well as the linked project are using double backslashes in the file path like if referencing another host(?) in the middle of the path string.

Typically an SMB path when connecting using the explorer in Windows looks like this: "\\hostname\share\folder\"

(edited with correct number of slashes)

This is because you have to inhibit the '' special meaning in most languages using another backslash. In the resulting string, there will be only 1 backslash

Yes I understand that you need to escape the backslash but what I do not understand is why there are more backslashes in the middle of the path than at the beginning. Also my example in the comment above was autocorrected by my phone.

Windows share example again:
"\\hostname\share\folder"

The original question by DemianSteelstone writes his path like this after escaping:
"\share\\folder\\file.ext"

The comment just above my first comment (the one made by you @chouquette) writes the file path as I would expect it to be written:
"folder\file.ext" (host name specified in other variable and connected to using a separate API call)

What I am trying to say is that your (chouquette) example looks correct while the other examples all have the same error(?) in common.

I will try this lib on iOS after vacation because it looks fun. If I am on the wrong track, any pointers would be appreciated :)

Oops, sorry about the confusion then :)
You're making a good point about the path being invalid, however I don't understand how the linked patch would change their handling... I guess I might have to find myself a SMB protocol doc

I know nothing about the smb protocol and I think you did a fine job with this lib. Was just worried when I saw the bug right after I made up my mind on using this lib and thought that a feature like move must be working and cannot really have gone unnoticed.

A newbie question, why are the paths specified using back slashes instead of forward slashes like in Linux or MacOS?

We face the same problem, how to solve?

the same problem here, any news ?